Browse Source

dynamite: Support default values for objects

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

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

@ -533,11 +533,23 @@ class OpenAPIBuilder implements Builder {
..optionalParameters.addAll(
schema.properties!.keys.map(
(final propertyName) => Parameter(
(final b) => b
..name = _toDartName(propertyName)
..toThis = true
..named = true
..required = (schema.required ?? []).contains(propertyName),
(final b) {
final propertySchema = schema.properties![propertyName]!;
b
..name = _toDartName(propertyName)
..toThis = true
..named = true
..required = (schema.required ?? []).contains(propertyName) &&
propertySchema.default_ == null;
if (propertySchema.default_ != null) {
final value = propertySchema.default_!.toString();
final result = resolveType(
propertySchema.type!,
propertySchema,
);
b.defaultTo = Code(_valueToEscapedValue(result.name, value));
}
},
),
),
),

Loading…
Cancel
Save