Browse Source

Merge pull request #154 from provokateurin/fix/non-required-bodies

dynamite: Fix non-required request bodies
pull/155/head
Kate 2 years ago committed by GitHub
parent
commit
2595f4ff17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      packages/dynamite/lib/src/openapi_builder.dart

11
packages/dynamite/lib/src/openapi_builder.dart

@ -652,19 +652,20 @@ class OpenAPIBuilder implements Builder {
);
switch (mimeType) {
case 'application/json':
final nullable = _isParameterNullable(
operation.requestBody!.required,
mediaType.schema?.default_,
);
b.optionalParameters.add(
Parameter(
(final b) => b
..name = _toDartName(result.name)
..type = refer(result.name)
..type = refer(_makeNullable(result.name, nullable))
..named = true
..required = operation.requestBody!.required ?? false,
),
);
final nullable = _isParameterNullable(
operation.requestBody!.required,
mediaType.schema?.default_,
);
if (nullable) {
code.write('if (${_toDartName(result.name)} != null) {');
}

Loading…
Cancel
Save