Browse Source

dynamite: split serializers

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/194/head
Nikolas Rimikis 2 years ago
parent
commit
3af5f2087c
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 16
      packages/dynamite/dynamite/lib/src/openapi_builder.dart

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

@ -1016,11 +1016,9 @@ class OpenAPIBuilder implements Builder {
'$name,',
],
'])',
r'final Serializers serializers = (_$serializers.toBuilder()..addPlugin(StandardJsonPlugin())',
if (state.hasContentString) ...[
'..addPlugin(const ContentStringPlugin())',
],
').build();',
r'final Serializers serializers = _$serializers;',
'',
'final Serializers jsonSerializers = (serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build();',
'',
'// coverage:ignore-start',
'T deserialize$prefix<T>(final Object data) => serializers.deserialize(data, specifiedType: FullType(T))! as T;',
@ -1288,14 +1286,14 @@ TypeResult resolveObject(
..type = refer('Object'),
),
)
..body = const Code('serializers.deserializeWith(serializer, json)!'),
..body = const Code('jsonSerializers.deserializeWith(serializer, json)!'),
),
Method(
(final b) => b
..name = 'toJson'
..returns = refer('Map<String, dynamic>')
..lambda = true
..body = const Code('serializers.serializeWith(serializer, this)! as Map<String, dynamic>'),
..body = const Code('jsonSerializers.serializeWith(serializer, this)! as Map<String, dynamic>'),
),
for (final propertyName in schema.properties!.keys) ...[
Method(
@ -1501,14 +1499,14 @@ TypeResult resolveType(
..type = refer('Object'),
),
)
..body = const Code('serializers.deserializeWith(serializer, json)!'),
..body = const Code('jsonSerializers.deserializeWith(serializer, json)!'),
),
Method(
(final b) => b
..name = 'toJson'
..returns = refer('Map<String, dynamic>')
..lambda = true
..body = const Code('serializers.serializeWith(serializer, this)! as Map<String, dynamic>'),
..body = const Code('jsonSerializers.serializeWith(serializer, this)! as Map<String, dynamic>'),
),
Method(
(final b) => b

Loading…
Cancel
Save