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()',
for (final type in state.resolvedTypeCombinations) ...[
...type.builderFactories,
],
...state.resolvedTypeCombinations
.map((final type) => type.serializers)
.expand((final element) => element)
.toSet(),
').build();',
'',
'Serializers get ${variablePrefix}Serializers => _serializers;',

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

@ -10,6 +10,9 @@ class TypeResultBase extends TypeResult {
@override
String? get _builderFactory => null;
@override
String? get _serializer => null;
@override
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
String? get _builderFactory => null;
@override
String? get _serializer => '..add($className.serializer)';
@override
String encode(
final String object, {

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

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

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

@ -13,6 +13,9 @@ class TypeResultMap extends TypeResult {
@override
String? get _builderFactory => '..addBuilderFactory($fullType, MapBuilder<String, ${subType.className}>.new)';
@override
String? get _serializer => null;
@override
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
String? get _builderFactory => '..addBuilderFactory($fullType, $name.new)';
@override
String? get _serializer => '..add($className.serializer)';
@override
String encode(
final String object, {

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

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

Loading…
Cancel
Save