From bee1440cd29835c6652813834e5c67f5c61d5975 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sun, 30 Jul 2023 17:02:48 +0200 Subject: [PATCH] refactor(dynamite): generate serializer ourself this avoids duplicate serializers being added --- .../dynamite/lib/src/openapi_builder.dart | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index 8ab1dd40..ba8e4788 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -415,8 +415,6 @@ class OpenAPIBuilder implements Builder { nullable: dartParameterNullable, ).dartType; - state.resolvedTypeCombinations.add(result); - if (result.name == 'String') { if (parameter.schema?.pattern != null) { code.write(''' @@ -621,7 +619,6 @@ class OpenAPIBuilder implements Builder { ), mediaType.schema!, ); - state.resolvedTypeCombinations.add(result); if (mimeType == '*/*' || mimeType == 'application/octet-stream' || @@ -713,14 +710,9 @@ class OpenAPIBuilder implements Builder { output.addAll(state.output.map((final e) => e.accept(emitter).toString())); - if (state.registeredJsonObjects.isNotEmpty) { + if (state.resolvedTypeCombinations.isNotEmpty) { output.addAll([ - '@SerializersFor(const [', - for (final name in state.registeredJsonObjects) ...[ - '$name,', - ], - '])', - r'final Serializers _serializers = (_$_serializers.toBuilder()', + 'final Serializers _serializers = (Serializers().toBuilder()', ...state.resolvedTypeCombinations .map((final type) => type.serializers) .expand((final element) => element) @@ -935,7 +927,6 @@ class State { final String prefix; final resolvedTypes = {}; - final registeredJsonObjects = {}; final output = []; final resolvedTypeCombinations = {}; } @@ -951,7 +942,6 @@ TypeResult resolveObject( }) { if (!state.resolvedTypes.contains('${state.prefix}$identifier')) { state.resolvedTypes.add('${state.prefix}$identifier'); - state.registeredJsonObjects.add('${state.prefix}$identifier'); state.output.add( Class( (final b) { @@ -1774,6 +1764,7 @@ TypeResult resolveType( ); } + state.resolvedTypeCombinations.add(result); return result; }