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!}',
],
]);
if (_toDartName(propertyName) != propertyName ||
propertySchema.isJsonString ||
extraJsonKeyValues != null) {
final hasDifferentName = _toDartName(propertyName) != propertyName;
final isJsonString = propertySchema.isJsonString;
final hasExtraJsonKeyValues =
extraJsonKeyValues != null && extraJsonKeyValues.containsKey(propertyName);
if (hasDifferentName || isJsonString || hasExtraJsonKeyValues) {
b.annotations.add(
refer('JsonKey').call(
[],
{
if (_toDartName(propertyName) != propertyName) ...{
if (hasDifferentName) ...{
'name': refer("'$propertyName'"),
},
if (propertySchema.isJsonString) ...{
if (isJsonString) ...{
'fromJson': refer('${result.name}.fromJsonString'),
'toJson': refer('${result.name}.toJsonString'),
},
if (extraJsonKeyValues != null && extraJsonKeyValues.containsKey(propertyName)) ...{
if (hasExtraJsonKeyValues) ...{
for (final key in extraJsonKeyValues[propertyName]!.keys) ...{
key: refer(extraJsonKeyValues[propertyName]![key]!),
},

Loading…
Cancel
Save