Skip to content

Commit

Permalink
Merge pull request #1213 from nextcloud/fix/dynamite/one_of_serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Leptopoda authored Dec 2, 2023
2 parents a8b4ac2 + ad31b9e commit e33678d
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 180 deletions.
4 changes: 2 additions & 2 deletions packages/dynamite/dynamite/lib/src/builder/generate_ofs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Iterable<Spec> generateSomeOf(
[
'value = object.$fieldName;',
'if (value != null) {',
' return ${result.serialize('value')}!;',
' return ${result.serialize('value', 'serializers')}!;',
'}',
],
'\n',
Expand Down Expand Up @@ -233,7 +233,7 @@ Iterable<Spec> generateSomeOf(
buffer.write('''
$dartName $fieldName;
try {
$fieldName = ${result.deserialize('data')};
$fieldName = ${result.deserialize('data', 'serializers')};
} catch (_) {}
''');
}
Expand Down
24 changes: 12 additions & 12 deletions packages/dynamite/dynamite_end_to_end_test/lib/any_of.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ class _$ObjectAnyOf0ObjectAnyOf1Serializer implements PrimitiveSerializer<$Objec
dynamic value;
value = object.objectAnyOf0;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(ObjectAnyOf0))!;
return serializers.serialize(value, specifiedType: const FullType(ObjectAnyOf0))!;
}
value = object.objectAnyOf1;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(ObjectAnyOf1))!;
return serializers.serialize(value, specifiedType: const FullType(ObjectAnyOf1))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -165,11 +165,11 @@ class _$ObjectAnyOf0ObjectAnyOf1Serializer implements PrimitiveSerializer<$Objec
}) {
ObjectAnyOf0? objectAnyOf0;
try {
objectAnyOf0 = _jsonSerializers.deserialize(data, specifiedType: const FullType(ObjectAnyOf0))! as ObjectAnyOf0;
objectAnyOf0 = serializers.deserialize(data, specifiedType: const FullType(ObjectAnyOf0))! as ObjectAnyOf0;
} catch (_) {}
ObjectAnyOf1? objectAnyOf1;
try {
objectAnyOf1 = _jsonSerializers.deserialize(data, specifiedType: const FullType(ObjectAnyOf1))! as ObjectAnyOf1;
objectAnyOf1 = serializers.deserialize(data, specifiedType: const FullType(ObjectAnyOf1))! as ObjectAnyOf1;
} catch (_) {}
return (objectAnyOf0: objectAnyOf0, objectAnyOf1: objectAnyOf1);
}
Expand Down Expand Up @@ -204,11 +204,11 @@ class _$MixedAnyOf1StringSerializer implements PrimitiveSerializer<$MixedAnyOf1S
dynamic value;
value = object.mixedAnyOf1;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(MixedAnyOf1))!;
return serializers.serialize(value, specifiedType: const FullType(MixedAnyOf1))!;
}
value = object.string;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(String))!;
return serializers.serialize(value, specifiedType: const FullType(String))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -222,11 +222,11 @@ class _$MixedAnyOf1StringSerializer implements PrimitiveSerializer<$MixedAnyOf1S
}) {
MixedAnyOf1? mixedAnyOf1;
try {
mixedAnyOf1 = _jsonSerializers.deserialize(data, specifiedType: const FullType(MixedAnyOf1))! as MixedAnyOf1;
mixedAnyOf1 = serializers.deserialize(data, specifiedType: const FullType(MixedAnyOf1))! as MixedAnyOf1;
} catch (_) {}
String? string;
try {
string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
string = serializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
return (mixedAnyOf1: mixedAnyOf1, string: string);
}
Expand Down Expand Up @@ -261,11 +261,11 @@ class _$NumStringSerializer implements PrimitiveSerializer<$NumString> {
dynamic value;
value = object.$num;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(num))!;
return serializers.serialize(value, specifiedType: const FullType(num))!;
}
value = object.string;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(String))!;
return serializers.serialize(value, specifiedType: const FullType(String))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -279,11 +279,11 @@ class _$NumStringSerializer implements PrimitiveSerializer<$NumString> {
}) {
num? $num;
try {
$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
$num = serializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {}
String? string;
try {
string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
string = serializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
return ($num: $num, string: string);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ class _$BaseOneOf1DoubleSerializer implements PrimitiveSerializer<$BaseOneOf1Dou
dynamic value;
value = object.baseOneOf1;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseOneOf1))!;
return serializers.serialize(value, specifiedType: const FullType(BaseOneOf1))!;
}
value = object.$double;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(double))!;
return serializers.serialize(value, specifiedType: const FullType(double))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -223,11 +223,11 @@ class _$BaseOneOf1DoubleSerializer implements PrimitiveSerializer<$BaseOneOf1Dou
}) {
BaseOneOf1? baseOneOf1;
try {
baseOneOf1 = _jsonSerializers.deserialize(data, specifiedType: const FullType(BaseOneOf1))! as BaseOneOf1;
baseOneOf1 = serializers.deserialize(data, specifiedType: const FullType(BaseOneOf1))! as BaseOneOf1;
} catch (_) {}
double? $double;
try {
$double = _jsonSerializers.deserialize(data, specifiedType: const FullType(double))! as double;
$double = serializers.deserialize(data, specifiedType: const FullType(double))! as double;
} catch (_) {}
return (baseOneOf1: baseOneOf1, $double: $double);
}
Expand Down Expand Up @@ -262,11 +262,11 @@ class _$BaseAnyOf1IntSerializer implements PrimitiveSerializer<$BaseAnyOf1Int> {
dynamic value;
value = object.baseAnyOf1;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseAnyOf1))!;
return serializers.serialize(value, specifiedType: const FullType(BaseAnyOf1))!;
}
value = object.$int;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(int))!;
return serializers.serialize(value, specifiedType: const FullType(int))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -280,11 +280,11 @@ class _$BaseAnyOf1IntSerializer implements PrimitiveSerializer<$BaseAnyOf1Int> {
}) {
BaseAnyOf1? baseAnyOf1;
try {
baseAnyOf1 = _jsonSerializers.deserialize(data, specifiedType: const FullType(BaseAnyOf1))! as BaseAnyOf1;
baseAnyOf1 = serializers.deserialize(data, specifiedType: const FullType(BaseAnyOf1))! as BaseAnyOf1;
} catch (_) {}
int? $int;
try {
$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
$int = serializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
return (baseAnyOf1: baseAnyOf1, $int: $int);
}
Expand Down Expand Up @@ -327,19 +327,19 @@ class _$BaseAllOfBaseAnyOfBaseNestedOneOf3BaseOneOfSerializer
dynamic value;
value = object.baseAllOf;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseAllOf))!;
return serializers.serialize(value, specifiedType: const FullType(BaseAllOf))!;
}
value = object.baseAnyOf;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseAnyOf))!;
return serializers.serialize(value, specifiedType: const FullType(BaseAnyOf))!;
}
value = object.baseNestedOneOf3;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseNestedOneOf3))!;
return serializers.serialize(value, specifiedType: const FullType(BaseNestedOneOf3))!;
}
value = object.baseOneOf;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseOneOf))!;
return serializers.serialize(value, specifiedType: const FullType(BaseOneOf))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -353,22 +353,22 @@ class _$BaseAllOfBaseAnyOfBaseNestedOneOf3BaseOneOfSerializer
}) {
BaseAllOf? baseAllOf;
try {
baseAllOf = _jsonSerializers.deserialize(data, specifiedType: const FullType(BaseAllOf))! as BaseAllOf;
baseAllOf = serializers.deserialize(data, specifiedType: const FullType(BaseAllOf))! as BaseAllOf;
} catch (_) {}
BaseAnyOf? baseAnyOf;
try {
baseAnyOf = ((_jsonSerializers.deserialize(data, specifiedType: const FullType(BaseAnyOf))! as BaseAnyOf)
..validateAnyOf());
baseAnyOf =
((serializers.deserialize(data, specifiedType: const FullType(BaseAnyOf))! as BaseAnyOf)..validateAnyOf());
} catch (_) {}
BaseNestedOneOf3? baseNestedOneOf3;
try {
baseNestedOneOf3 =
_jsonSerializers.deserialize(data, specifiedType: const FullType(BaseNestedOneOf3))! as BaseNestedOneOf3;
serializers.deserialize(data, specifiedType: const FullType(BaseNestedOneOf3))! as BaseNestedOneOf3;
} catch (_) {}
BaseOneOf? baseOneOf;
try {
baseOneOf = ((_jsonSerializers.deserialize(data, specifiedType: const FullType(BaseOneOf))! as BaseOneOf)
..validateOneOf());
baseOneOf =
((serializers.deserialize(data, specifiedType: const FullType(BaseOneOf))! as BaseOneOf)..validateOneOf());
} catch (_) {}
return (baseAllOf: baseAllOf, baseAnyOf: baseAnyOf, baseNestedOneOf3: baseNestedOneOf3, baseOneOf: baseOneOf);
}
Expand Down Expand Up @@ -411,19 +411,19 @@ class _$BaseAllOfBaseAnyOfBaseNestedAnyOf3BaseOneOfSerializer
dynamic value;
value = object.baseAllOf;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseAllOf))!;
return serializers.serialize(value, specifiedType: const FullType(BaseAllOf))!;
}
value = object.baseAnyOf;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseAnyOf))!;
return serializers.serialize(value, specifiedType: const FullType(BaseAnyOf))!;
}
value = object.baseNestedAnyOf3;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseNestedAnyOf3))!;
return serializers.serialize(value, specifiedType: const FullType(BaseNestedAnyOf3))!;
}
value = object.baseOneOf;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(BaseOneOf))!;
return serializers.serialize(value, specifiedType: const FullType(BaseOneOf))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -437,22 +437,22 @@ class _$BaseAllOfBaseAnyOfBaseNestedAnyOf3BaseOneOfSerializer
}) {
BaseAllOf? baseAllOf;
try {
baseAllOf = _jsonSerializers.deserialize(data, specifiedType: const FullType(BaseAllOf))! as BaseAllOf;
baseAllOf = serializers.deserialize(data, specifiedType: const FullType(BaseAllOf))! as BaseAllOf;
} catch (_) {}
BaseAnyOf? baseAnyOf;
try {
baseAnyOf = ((_jsonSerializers.deserialize(data, specifiedType: const FullType(BaseAnyOf))! as BaseAnyOf)
..validateAnyOf());
baseAnyOf =
((serializers.deserialize(data, specifiedType: const FullType(BaseAnyOf))! as BaseAnyOf)..validateAnyOf());
} catch (_) {}
BaseNestedAnyOf3? baseNestedAnyOf3;
try {
baseNestedAnyOf3 =
_jsonSerializers.deserialize(data, specifiedType: const FullType(BaseNestedAnyOf3))! as BaseNestedAnyOf3;
serializers.deserialize(data, specifiedType: const FullType(BaseNestedAnyOf3))! as BaseNestedAnyOf3;
} catch (_) {}
BaseOneOf? baseOneOf;
try {
baseOneOf = ((_jsonSerializers.deserialize(data, specifiedType: const FullType(BaseOneOf))! as BaseOneOf)
..validateOneOf());
baseOneOf =
((serializers.deserialize(data, specifiedType: const FullType(BaseOneOf))! as BaseOneOf)..validateOneOf());
} catch (_) {}
return (baseAllOf: baseAllOf, baseAnyOf: baseAnyOf, baseNestedAnyOf3: baseNestedAnyOf3, baseOneOf: baseOneOf);
}
Expand Down
24 changes: 12 additions & 12 deletions packages/dynamite/dynamite_end_to_end_test/lib/one_of.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ class _$ObjectOneOf0ObjectOneOf1Serializer implements PrimitiveSerializer<$Objec
dynamic value;
value = object.objectOneOf0;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(ObjectOneOf0))!;
return serializers.serialize(value, specifiedType: const FullType(ObjectOneOf0))!;
}
value = object.objectOneOf1;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(ObjectOneOf1))!;
return serializers.serialize(value, specifiedType: const FullType(ObjectOneOf1))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -165,11 +165,11 @@ class _$ObjectOneOf0ObjectOneOf1Serializer implements PrimitiveSerializer<$Objec
}) {
ObjectOneOf0? objectOneOf0;
try {
objectOneOf0 = _jsonSerializers.deserialize(data, specifiedType: const FullType(ObjectOneOf0))! as ObjectOneOf0;
objectOneOf0 = serializers.deserialize(data, specifiedType: const FullType(ObjectOneOf0))! as ObjectOneOf0;
} catch (_) {}
ObjectOneOf1? objectOneOf1;
try {
objectOneOf1 = _jsonSerializers.deserialize(data, specifiedType: const FullType(ObjectOneOf1))! as ObjectOneOf1;
objectOneOf1 = serializers.deserialize(data, specifiedType: const FullType(ObjectOneOf1))! as ObjectOneOf1;
} catch (_) {}
return (objectOneOf0: objectOneOf0, objectOneOf1: objectOneOf1);
}
Expand Down Expand Up @@ -204,11 +204,11 @@ class _$MixedOneOf1StringSerializer implements PrimitiveSerializer<$MixedOneOf1S
dynamic value;
value = object.mixedOneOf1;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(MixedOneOf1))!;
return serializers.serialize(value, specifiedType: const FullType(MixedOneOf1))!;
}
value = object.string;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(String))!;
return serializers.serialize(value, specifiedType: const FullType(String))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -222,11 +222,11 @@ class _$MixedOneOf1StringSerializer implements PrimitiveSerializer<$MixedOneOf1S
}) {
MixedOneOf1? mixedOneOf1;
try {
mixedOneOf1 = _jsonSerializers.deserialize(data, specifiedType: const FullType(MixedOneOf1))! as MixedOneOf1;
mixedOneOf1 = serializers.deserialize(data, specifiedType: const FullType(MixedOneOf1))! as MixedOneOf1;
} catch (_) {}
String? string;
try {
string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
string = serializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
return (mixedOneOf1: mixedOneOf1, string: string);
}
Expand Down Expand Up @@ -261,11 +261,11 @@ class _$NumStringSerializer implements PrimitiveSerializer<$NumString> {
dynamic value;
value = object.$num;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(num))!;
return serializers.serialize(value, specifiedType: const FullType(num))!;
}
value = object.string;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(String))!;
return serializers.serialize(value, specifiedType: const FullType(String))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -279,11 +279,11 @@ class _$NumStringSerializer implements PrimitiveSerializer<$NumString> {
}) {
num? $num;
try {
$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
$num = serializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {}
String? string;
try {
string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
string = serializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
return ($num: $num, string: string);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ class _$NumStringSerializer implements PrimitiveSerializer<$NumString> {
dynamic value;
value = object.$num;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(num))!;
return serializers.serialize(value, specifiedType: const FullType(num))!;
}
value = object.string;
if (value != null) {
return _jsonSerializers.serialize(value, specifiedType: const FullType(String))!;
return serializers.serialize(value, specifiedType: const FullType(String))!;
}
// Should not be possible after validation.
throw StateError('Tried to serialize without any value.');
Expand All @@ -113,11 +113,11 @@ class _$NumStringSerializer implements PrimitiveSerializer<$NumString> {
}) {
num? $num;
try {
$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
$num = serializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {}
String? string;
try {
string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
string = serializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
return ($num: $num, string: string);
}
Expand Down
Loading

0 comments on commit e33678d

Please sign in to comment.