From 12e5112575db63a51eb96323d01cc3e6a9996bc2 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 19 Dec 2023 13:27:53 +0100 Subject: [PATCH] chore(dynamite): remove unused header serializer generation Signed-off-by: Nikolas Rimikis --- .../lib/src/builder/header_serializer.dart | 139 ------------------ 1 file changed, 139 deletions(-) delete mode 100644 packages/dynamite/dynamite/lib/src/builder/header_serializer.dart diff --git a/packages/dynamite/dynamite/lib/src/builder/header_serializer.dart b/packages/dynamite/dynamite/lib/src/builder/header_serializer.dart deleted file mode 100644 index ca05a599536..00000000000 --- a/packages/dynamite/dynamite/lib/src/builder/header_serializer.dart +++ /dev/null @@ -1,139 +0,0 @@ -import 'package:code_builder/code_builder.dart'; -import 'package:dynamite/src/builder/resolve_type.dart'; -import 'package:dynamite/src/builder/state.dart'; -import 'package:dynamite/src/helpers/dart_helpers.dart'; -import 'package:dynamite/src/helpers/dynamite.dart'; -import 'package:dynamite/src/models/openapi.dart' as openapi; -import 'package:dynamite/src/models/type_result.dart'; - -Spec buildHeaderSerializer( - final State state, - final String identifier, - final openapi.OpenAPI spec, - final openapi.Schema schema, -) => - Class( - (final b) => b - ..name = '_\$${identifier}Serializer' - ..implements.add(refer('StructuredSerializer<$identifier>')) - ..fields.addAll([ - Field( - (final b) => b - ..name = 'types' - ..modifier = FieldModifier.final$ - ..type = refer('Iterable') - ..annotations.add(refer('override')) - ..assignment = Code('const [$identifier, _\$$identifier]'), - ), - Field( - (final b) => b - ..name = 'wireName' - ..modifier = FieldModifier.final$ - ..type = refer('String') - ..annotations.add(refer('override')) - ..assignment = Code("r'$identifier'"), - ), - ]) - ..methods.addAll([ - Method((final b) { - b - ..name = 'serialize' - ..returns = refer('Iterable') - ..annotations.add(refer('override')) - ..requiredParameters.addAll([ - Parameter( - (final b) => b - ..name = 'serializers' - ..type = refer('Serializers'), - ), - Parameter( - (final b) => b - ..name = 'object' - ..type = refer(identifier), - ), - ]) - ..optionalParameters.add( - Parameter( - (final b) => b - ..name = 'specifiedType' - ..type = refer('FullType') - ..named = true - ..defaultTo = const Code('FullType.unspecified'), - ), - ) - ..body = const Code('throw UnimplementedError();'); - }), - Method((final b) { - b - ..name = 'deserialize' - ..returns = refer(identifier) - ..annotations.add(refer('override')) - ..requiredParameters.addAll([ - Parameter( - (final b) => b - ..name = 'serializers' - ..type = refer('Serializers'), - ), - Parameter( - (final b) => b - ..name = 'serialized' - ..type = refer('Iterable'), - ), - ]) - ..optionalParameters.add( - Parameter( - (final b) => b - ..name = 'specifiedType' - ..type = refer('FullType') - ..named = true - ..defaultTo = const Code('FullType.unspecified'), - ), - ) - ..body = Code(''' -final result = new ${identifier}Builder(); - -final iterator = serialized.iterator; -while (iterator.moveNext()) { - final key = iterator.current! as String; - iterator.moveNext(); - final value = iterator.current! as String; - switch (key) { - ${deserializeProperty(state, identifier, spec, schema).join('\n')} - } -} - -return result.build(); -'''); - }), - ]), - ); - -Iterable deserializeProperty( - final State state, - final String identifier, - final openapi.OpenAPI spec, - final openapi.Schema schema, -) sync* { - for (final property in schema.properties!.entries) { - final propertyName = property.key; - final propertySchema = property.value; - final result = resolveType( - spec, - state, - '${identifier}_${toDartName(propertyName, uppercaseFirstCharacter: true)}', - propertySchema, - nullable: isDartParameterNullable(schema.required.contains(propertyName), propertySchema), - ); - - yield "case '$propertyName':"; - if (result.className != 'String') { - if (result is TypeResultBase || result is TypeResultEnum || result is TypeResultSomeOf) { - yield 'result.${toDartName(propertyName)} = ${result.deserialize(result.decode('value!'))};'; - } else { - yield 'result.${toDartName(propertyName)}.replace(${result.deserialize(result.decode('value!'))});'; - } - } else { - yield 'result.${toDartName(propertyName)} = value!;'; - } - } -}