diff --git a/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.dart b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.dart index 2ca87c30..bcd08ca5 100644 --- a/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.dart +++ b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.dart @@ -327,7 +327,65 @@ abstract class NewPet implements NewPetInterface, Built { Map toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map; // coverage:ignore-end - static Serializer get serializer => _$newPetSerializer; + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$NewPetSerializer(); +} + +class _$NewPetSerializer implements StructuredSerializer { + const _$NewPetSerializer(); + + @override + Iterable get types => const [NewPet, _$NewPet]; + + @override + String get wireName => r'NewPet'; + + @override + Iterable serialize( + Serializers serializers, + NewPet object, { + FullType specifiedType = FullType.unspecified, + }) { + final result = [ + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + ]; + Object? value; + value = object.tag; + if (value != null) { + result + ..add('tag') + ..add( + serializers.serialize(value, specifiedType: const FullType(String)), + ); + } + + return result; + } + + @override + NewPet deserialize( + Serializers serializers, + Iterable serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = NewPetBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final value = iterator.current; + switch (key) { + case 'name': + result.name = (serializers.deserialize(value, specifiedType: const FullType(String))! as String); + case 'tag': + result.tag = (serializers.deserialize(value, specifiedType: const FullType(String)) as String); + } + } + + return result.build(); + } } @BuiltValue(instantiable: false) @@ -377,7 +435,57 @@ abstract class Error implements ErrorInterface, Built { Map toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map; // coverage:ignore-end - static Serializer get serializer => _$errorSerializer; + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ErrorSerializer(); +} + +class _$ErrorSerializer implements StructuredSerializer { + const _$ErrorSerializer(); + + @override + Iterable get types => const [Error, _$Error]; + + @override + String get wireName => r'Error'; + + @override + Iterable serialize( + Serializers serializers, + Error object, { + FullType specifiedType = FullType.unspecified, + }) { + final result = [ + 'code', + serializers.serialize(object.code, specifiedType: const FullType(int)), + 'message', + serializers.serialize(object.message, specifiedType: const FullType(String)), + ]; + return result; + } + + @override + Error deserialize( + Serializers serializers, + Iterable serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ErrorBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final value = iterator.current; + switch (key) { + case 'code': + result.code = (serializers.deserialize(value, specifiedType: const FullType(int))! as int); + case 'message': + result.message = (serializers.deserialize(value, specifiedType: const FullType(String))! as String); + } + } + + return result.build(); + } } // coverage:ignore-start diff --git a/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.g.dart b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.g.dart index 6786ccb0..30c14c1e 100644 --- a/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.g.dart +++ b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.g.dart @@ -6,55 +6,7 @@ part of 'petstore.openapi.dart'; // BuiltValueGenerator // ************************************************************************** -Serializer _$newPetSerializer = _$NewPetSerializer(); Serializer _$petSerializer = _$PetSerializer(); -Serializer _$errorSerializer = _$ErrorSerializer(); - -class _$NewPetSerializer implements StructuredSerializer { - @override - final Iterable types = const [NewPet, _$NewPet]; - @override - final String wireName = 'NewPet'; - - @override - Iterable serialize(Serializers serializers, NewPet object, {FullType specifiedType = FullType.unspecified}) { - final result = [ - 'name', - serializers.serialize(object.name, specifiedType: const FullType(String)), - ]; - Object? value; - value = object.tag; - if (value != null) { - result - ..add('tag') - ..add(serializers.serialize(value, specifiedType: const FullType(String))); - } - return result; - } - - @override - NewPet deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = NewPetBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current! as String; - iterator.moveNext(); - final Object? value = iterator.current; - switch (key) { - case 'name': - result.name = serializers.deserialize(value, specifiedType: const FullType(String))! as String; - break; - case 'tag': - result.tag = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; - break; - } - } - - return result.build(); - } -} class _$PetSerializer implements StructuredSerializer { @override @@ -107,48 +59,6 @@ class _$PetSerializer implements StructuredSerializer { } } -class _$ErrorSerializer implements StructuredSerializer { - @override - final Iterable types = const [Error, _$Error]; - @override - final String wireName = 'Error'; - - @override - Iterable serialize(Serializers serializers, Error object, {FullType specifiedType = FullType.unspecified}) { - final result = [ - 'code', - serializers.serialize(object.code, specifiedType: const FullType(int)), - 'message', - serializers.serialize(object.message, specifiedType: const FullType(String)), - ]; - - return result; - } - - @override - Error deserialize(Serializers serializers, Iterable serialized, - {FullType specifiedType = FullType.unspecified}) { - final result = ErrorBuilder(); - - final iterator = serialized.iterator; - while (iterator.moveNext()) { - final key = iterator.current! as String; - iterator.moveNext(); - final Object? value = iterator.current; - switch (key) { - case 'code': - result.code = serializers.deserialize(value, specifiedType: const FullType(int))! as int; - break; - case 'message': - result.message = serializers.deserialize(value, specifiedType: const FullType(String))! as String; - break; - } - } - - return result.build(); - } -} - abstract mixin class NewPetInterfaceBuilder { void replace(NewPetInterface other); void update(void Function(NewPetInterfaceBuilder) updates);