Browse Source

dynamite: Simplify JsonKey annotations

pull/166/head
jld3103 2 years ago
parent
commit
22684cde70
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 14
      packages/dynamite/lib/src/openapi_builder.dart

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

@ -1168,21 +1168,23 @@ TypeResult resolveObject(
'/// ${propertySchema.description!}', '/// ${propertySchema.description!}',
], ],
]); ]);
if (_toDartName(propertyName) != propertyName || final hasDifferentName = _toDartName(propertyName) != propertyName;
propertySchema.isJsonString || final isJsonString = propertySchema.isJsonString;
extraJsonKeyValues != null) { final hasExtraJsonKeyValues =
extraJsonKeyValues != null && extraJsonKeyValues.containsKey(propertyName);
if (hasDifferentName || isJsonString || hasExtraJsonKeyValues) {
b.annotations.add( b.annotations.add(
refer('JsonKey').call( refer('JsonKey').call(
[], [],
{ {
if (_toDartName(propertyName) != propertyName) ...{ if (hasDifferentName) ...{
'name': refer("'$propertyName'"), 'name': refer("'$propertyName'"),
}, },
if (propertySchema.isJsonString) ...{ if (isJsonString) ...{
'fromJson': refer('${result.name}.fromJsonString'), 'fromJson': refer('${result.name}.fromJsonString'),
'toJson': refer('${result.name}.toJsonString'), 'toJson': refer('${result.name}.toJsonString'),
}, },
if (extraJsonKeyValues != null && extraJsonKeyValues.containsKey(propertyName)) ...{ if (hasExtraJsonKeyValues) ...{
for (final key in extraJsonKeyValues[propertyName]!.keys) ...{ for (final key in extraJsonKeyValues[propertyName]!.keys) ...{
key: refer(extraJsonKeyValues[propertyName]![key]!), key: refer(extraJsonKeyValues[propertyName]![key]!),
}, },

Loading…
Cancel
Save