From e33b45856d1bc68bd506d5390db555e4dfcd7bd2 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 14 Dec 2022 15:13:27 +0100 Subject: [PATCH] dynamite: Fix non-required request bodies --- packages/dynamite/lib/src/openapi_builder.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/lib/src/openapi_builder.dart index 4cd6efe1..6bad8177 100644 --- a/packages/dynamite/lib/src/openapi_builder.dart +++ b/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) {'); }