Browse Source

fix(dynamite): add serializers of parameter types

pull/501/head
Nikolas Rimikis 1 year ago
parent
commit
6db0cb3179
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 7
      packages/dynamite/dynamite/lib/src/openapi_builder.dart
  2. 3
      packages/dynamite/dynamite/lib/src/type_result/base.dart
  3. 3
      packages/dynamite/dynamite/lib/src/type_result/enum.dart
  4. 3
      packages/dynamite/dynamite/lib/src/type_result/list.dart
  5. 3
      packages/dynamite/dynamite/lib/src/type_result/map.dart
  6. 3
      packages/dynamite/dynamite/lib/src/type_result/object.dart
  7. 22
      packages/dynamite/dynamite/lib/src/type_result/type_result.dart

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

@ -721,9 +721,10 @@ class OpenAPIBuilder implements Builder {
], ],
'])', '])',
r'final Serializers _serializers = (_$_serializers.toBuilder()', r'final Serializers _serializers = (_$_serializers.toBuilder()',
for (final type in state.resolvedTypeCombinations) ...[ ...state.resolvedTypeCombinations
...type.builderFactories, .map((final type) => type.serializers)
], .expand((final element) => element)
.toSet(),
').build();', ').build();',
'', '',
'Serializers get ${variablePrefix}Serializers => _serializers;', 'Serializers get ${variablePrefix}Serializers => _serializers;',

3
packages/dynamite/dynamite/lib/src/type_result/base.dart

@ -10,6 +10,9 @@ class TypeResultBase extends TypeResult {
@override @override
String? get _builderFactory => null; String? get _builderFactory => null;
@override
String? get _serializer => null;
@override @override
String serialize(final String object) => object; String serialize(final String object) => object;

3
packages/dynamite/dynamite/lib/src/type_result/enum.dart

@ -13,6 +13,9 @@ class TypeResultEnum extends TypeResult {
@override @override
String? get _builderFactory => null; String? get _builderFactory => null;
@override
String? get _serializer => '..add($className.serializer)';
@override @override
String encode( String encode(
final String object, { final String object, {

3
packages/dynamite/dynamite/lib/src/type_result/list.dart

@ -13,6 +13,9 @@ class TypeResultList extends TypeResult {
@override @override
String? get _builderFactory => '..addBuilderFactory($fullType, ListBuilder<${subType.className}>.new)'; String? get _builderFactory => '..addBuilderFactory($fullType, ListBuilder<${subType.className}>.new)';
@override
String? get _serializer => null;
@override @override
String encode( String encode(
final String object, { final String object, {

3
packages/dynamite/dynamite/lib/src/type_result/map.dart

@ -13,6 +13,9 @@ class TypeResultMap extends TypeResult {
@override @override
String? get _builderFactory => '..addBuilderFactory($fullType, MapBuilder<String, ${subType.className}>.new)'; String? get _builderFactory => '..addBuilderFactory($fullType, MapBuilder<String, ${subType.className}>.new)';
@override
String? get _serializer => null;
@override @override
TypeResultMap get dartType => TypeResultMap('Map', subType, nullable: nullable); TypeResultMap get dartType => TypeResultMap('Map', subType, nullable: nullable);

3
packages/dynamite/dynamite/lib/src/type_result/object.dart

@ -16,6 +16,9 @@ class TypeResultObject extends TypeResult {
@override @override
String? get _builderFactory => '..addBuilderFactory($fullType, $name.new)'; String? get _builderFactory => '..addBuilderFactory($fullType, $name.new)';
@override
String? get _serializer => '..add($className.serializer)';
@override @override
String encode( String encode(
final String object, { final String object, {

22
packages/dynamite/dynamite/lib/src/type_result/type_result.dart

@ -43,14 +43,20 @@ abstract class TypeResult {
return 'FullType($className)'; return 'FullType($className)';
} }
List<String> get builderFactories => [ Iterable<String> get serializers sync* {
for (final class_ in generics) ...[ for (final class_ in generics) {
...class_.builderFactories, yield* class_.serializers;
], }
if (_builderFactory != null) ...[
_builderFactory!, if (_builderFactory != null) {
], yield _builderFactory!;
]; }
if (_serializer != null) {
yield _serializer!;
}
}
String? get _serializer;
String? get _builderFactory; String? get _builderFactory;

Loading…
Cancel
Save