Browse Source

dynamite: reimplement default values

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/194/head
Nikolas Rimikis 2 years ago
parent
commit
263a8b0199
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 47
      packages/dynamite/lib/src/openapi_builder.dart

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

@ -1472,6 +1472,53 @@ TypeResult resolveObject(
..type = MethodType.getter, ..type = MethodType.getter,
), ),
]); ]);
final defaults = <String>[];
for (final propertyName in schema.properties!.keys) {
final propertySchema = schema.properties![propertyName]!;
if (propertySchema.default_ != null) {
final value = propertySchema.default_!.toString();
final result = resolveType(
spec,
state,
propertySchema.type!,
propertySchema,
);
defaults.add('..${_toDartName(propertyName)} = ${_valueToEscapedValue(result, value)}');
}
}
if (defaults.isNotEmpty) {
b.methods.add(
Method(
(final b) => b
..name = '_defaults'
..returns = refer('void')
..static = true
..lambda = true
..annotations.add(
refer('BuiltValueHook').call(
[],
{
'initializeBuilder': refer('true'),
},
),
)
..requiredParameters.add(
Parameter(
(final b) => b
..name = 'b'
..type = refer('${state.prefix}${identifier}Builder'),
),
)
..body = Code(
<String?>[
'b',
...defaults,
].join(),
),
),
);
}
}, },
), ),
); );

Loading…
Cancel
Save