From e10d03fecda82edb4f81cd216795fd8c13328630 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 2 Sep 2023 20:32:45 +0200 Subject: [PATCH] refactor(dynamite): cleanup isPrameterNullable Signed-off-by: Nikolas Rimikis --- .../dynamite/lib/src/openapi_builder.dart | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index 87a33f1f..6af6c103 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -376,8 +376,7 @@ class OpenAPIBuilder implements Builder { for (final parameter in parameters) { final dartParameterNullable = _isDartParameterNullable( parameter.required, - parameter.schema?.nullable, - parameter.schema?.default_, + parameter.schema, ); final dartParameterRequired = _isDartParameterRequired(parameter); @@ -484,8 +483,7 @@ class OpenAPIBuilder implements Builder { final dartParameterNullable = _isDartParameterNullable( operation.requestBody!.required, - mediaType.schema?.nullable, - mediaType.schema?.default_, + mediaType.schema, ); final result = resolveType( @@ -829,10 +827,9 @@ String _toFieldName(final String dartName, final String type) => dartName == typ bool _isDartParameterNullable( final bool? required, - final bool? nullable, - final dynamic default_, + final Schema? schema, ) => - (!(required ?? false) && default_ == null) || (nullable ?? false); + (!(required ?? false) && schema?.default_ == null) || (schema?.nullable ?? false); bool _isDartParameterRequired(final spec_parameter.Parameter parameter) => _isRequired(parameter.required, parameter.schema?.default_); @@ -983,8 +980,7 @@ TypeResult resolveObject( propertySchema, nullable: _isDartParameterNullable( schema.required?.contains(propertyName), - propertySchema.nullable, - propertySchema.default_, + propertySchema, ), ); @@ -1160,11 +1156,7 @@ TypeResult resolveObject( state, '${identifier}_${_toDartName(propertyName, uppercaseFirstCharacter: true)}', propertySchema, - nullable: _isDartParameterNullable( - schema.required?.contains(propertyName), - propertySchema.nullable, - propertySchema.default_, - ), + nullable: _isDartParameterNullable(schema.required?.contains(propertyName), propertySchema), ); return [