Browse Source

Merge pull request #132 from provokateurin/feature/object-default-values

dynamite: Support default values for objects
pull/134/head
Kate 2 years ago committed by GitHub
parent
commit
4a043e82db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      packages/dynamite/lib/src/openapi_builder.dart

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

@ -533,11 +533,23 @@ class OpenAPIBuilder implements Builder {
..optionalParameters.addAll( ..optionalParameters.addAll(
schema.properties!.keys.map( schema.properties!.keys.map(
(final propertyName) => Parameter( (final propertyName) => Parameter(
(final b) => b (final b) {
final propertySchema = schema.properties![propertyName]!;
b
..name = _toDartName(propertyName) ..name = _toDartName(propertyName)
..toThis = true ..toThis = true
..named = true ..named = true
..required = (schema.required ?? []).contains(propertyName), ..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