|
|
@ -16,7 +16,7 @@ TypeResult resolveAllOf( |
|
|
|
final bool nullable = false, |
|
|
|
final bool nullable = false, |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
final result = TypeResultObject( |
|
|
|
final result = TypeResultObject( |
|
|
|
'${state.classPrefix}$identifier', |
|
|
|
identifier, |
|
|
|
nullable: nullable, |
|
|
|
nullable: nullable, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -55,7 +55,7 @@ TypeResult resolveAllOf( |
|
|
|
|
|
|
|
|
|
|
|
state.output.add( |
|
|
|
state.output.add( |
|
|
|
buildBuiltClass( |
|
|
|
buildBuiltClass( |
|
|
|
'${state.classPrefix}$identifier', |
|
|
|
identifier, |
|
|
|
interfaces: interfaces, |
|
|
|
interfaces: interfaces, |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
@ -75,7 +75,7 @@ TypeResult resolveOfs( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final result = TypeResultObject( |
|
|
|
final result = TypeResultObject( |
|
|
|
'${state.classPrefix}$identifier', |
|
|
|
identifier, |
|
|
|
nullable: nullable, |
|
|
|
nullable: nullable, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -94,13 +94,13 @@ TypeResult resolveOfs( |
|
|
|
|
|
|
|
|
|
|
|
final fields = <String, String>{}; |
|
|
|
final fields = <String, String>{}; |
|
|
|
for (final result in results) { |
|
|
|
for (final result in results) { |
|
|
|
final dartName = toDartName(result.name.replaceFirst(state.classPrefix, '')); |
|
|
|
final dartName = toDartName(result.name); |
|
|
|
fields[result.name] = toFieldName(dartName, result.name.replaceFirst(state.classPrefix, '')); |
|
|
|
fields[result.name] = toFieldName(dartName, result.name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state.output.addAll([ |
|
|
|
state.output.addAll([ |
|
|
|
buildBuiltClass( |
|
|
|
buildBuiltClass( |
|
|
|
'${state.classPrefix}$identifier', |
|
|
|
identifier, |
|
|
|
methods: BuiltList.build((final b) { |
|
|
|
methods: BuiltList.build((final b) { |
|
|
|
b.add( |
|
|
|
b.add( |
|
|
|
Method( |
|
|
|
Method( |
|
|
@ -132,8 +132,8 @@ TypeResult resolveOfs( |
|
|
|
), |
|
|
|
), |
|
|
|
Class( |
|
|
|
Class( |
|
|
|
(final b) => b |
|
|
|
(final b) => b |
|
|
|
..name = '_\$${state.classPrefix}${identifier}Serializer' |
|
|
|
..name = '_\$${identifier}Serializer' |
|
|
|
..implements.add(refer('PrimitiveSerializer<${state.classPrefix}$identifier>')) |
|
|
|
..implements.add(refer('PrimitiveSerializer<$identifier>')) |
|
|
|
..fields.addAll([ |
|
|
|
..fields.addAll([ |
|
|
|
Field( |
|
|
|
Field( |
|
|
|
(final b) => b |
|
|
|
(final b) => b |
|
|
@ -141,7 +141,7 @@ TypeResult resolveOfs( |
|
|
|
..modifier = FieldModifier.final$ |
|
|
|
..modifier = FieldModifier.final$ |
|
|
|
..type = refer('Iterable<Type>') |
|
|
|
..type = refer('Iterable<Type>') |
|
|
|
..annotations.add(refer('override')) |
|
|
|
..annotations.add(refer('override')) |
|
|
|
..assignment = Code('const [${state.classPrefix}$identifier, _\$${state.classPrefix}$identifier]'), |
|
|
|
..assignment = Code('const [$identifier, _\$$identifier]'), |
|
|
|
), |
|
|
|
), |
|
|
|
Field( |
|
|
|
Field( |
|
|
|
(final b) => b |
|
|
|
(final b) => b |
|
|
@ -149,7 +149,7 @@ TypeResult resolveOfs( |
|
|
|
..modifier = FieldModifier.final$ |
|
|
|
..modifier = FieldModifier.final$ |
|
|
|
..type = refer('String') |
|
|
|
..type = refer('String') |
|
|
|
..annotations.add(refer('override')) |
|
|
|
..annotations.add(refer('override')) |
|
|
|
..assignment = Code("r'${state.classPrefix}$identifier'"), |
|
|
|
..assignment = Code("r'$identifier'"), |
|
|
|
), |
|
|
|
), |
|
|
|
]) |
|
|
|
]) |
|
|
|
..methods.addAll([ |
|
|
|
..methods.addAll([ |
|
|
@ -167,7 +167,7 @@ TypeResult resolveOfs( |
|
|
|
Parameter( |
|
|
|
Parameter( |
|
|
|
(final b) => b |
|
|
|
(final b) => b |
|
|
|
..name = 'object' |
|
|
|
..name = 'object' |
|
|
|
..type = refer('${state.classPrefix}$identifier'), |
|
|
|
..type = refer(identifier), |
|
|
|
), |
|
|
|
), |
|
|
|
]) |
|
|
|
]) |
|
|
|
..optionalParameters.add( |
|
|
|
..optionalParameters.add( |
|
|
@ -184,7 +184,7 @@ TypeResult resolveOfs( |
|
|
|
Method((final b) { |
|
|
|
Method((final b) { |
|
|
|
b |
|
|
|
b |
|
|
|
..name = 'deserialize' |
|
|
|
..name = 'deserialize' |
|
|
|
..returns = refer('${state.classPrefix}$identifier') |
|
|
|
..returns = refer(identifier) |
|
|
|
..annotations.add(refer('override')) |
|
|
|
..annotations.add(refer('override')) |
|
|
|
..requiredParameters.addAll([ |
|
|
|
..requiredParameters.addAll([ |
|
|
|
Parameter( |
|
|
|
Parameter( |
|
|
@ -209,7 +209,7 @@ TypeResult resolveOfs( |
|
|
|
) |
|
|
|
) |
|
|
|
..body = Code( |
|
|
|
..body = Code( |
|
|
|
<String>[ |
|
|
|
<String>[ |
|
|
|
'final result = new ${state.classPrefix}${identifier}Builder()', |
|
|
|
'final result = new ${identifier}Builder()', |
|
|
|
'..data = JsonObject(data);', |
|
|
|
'..data = JsonObject(data);', |
|
|
|
if (schema.discriminator != null) ...[ |
|
|
|
if (schema.discriminator != null) ...[ |
|
|
|
'if (data is! Iterable) {', |
|
|
|
'if (data is! Iterable) {', |
|
|
@ -231,12 +231,11 @@ TypeResult resolveOfs( |
|
|
|
], |
|
|
|
], |
|
|
|
for (final result in results) ...[ |
|
|
|
for (final result in results) ...[ |
|
|
|
if (schema.discriminator != null) ...[ |
|
|
|
if (schema.discriminator != null) ...[ |
|
|
|
"if (discriminator == '${result.name.replaceFirst(state.classPrefix, '')}'", |
|
|
|
"if (discriminator == '${result.name}'", |
|
|
|
if (schema.discriminator!.mapping != null && schema.discriminator!.mapping!.isNotEmpty) ...[ |
|
|
|
if (schema.discriminator!.mapping != null && schema.discriminator!.mapping!.isNotEmpty) ...[ |
|
|
|
for (final key in schema.discriminator!.mapping!.entries |
|
|
|
for (final key in schema.discriminator!.mapping!.entries |
|
|
|
.where( |
|
|
|
.where( |
|
|
|
(final entry) => |
|
|
|
(final entry) => entry.value.endsWith('/${result.name}'), |
|
|
|
entry.value.endsWith('/${result.name.replaceFirst(state.classPrefix, '')}'), |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
.map((final entry) => entry.key)) ...[ |
|
|
|
.map((final entry) => entry.key)) ...[ |
|
|
|
" || discriminator == '$key'", |
|
|
|
" || discriminator == '$key'", |
|
|
|