Repository navigation
Fix properties becoming required when a sibling uses allOf - #475
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
This also affects us. We have a NestJS backend whose spec is generated by Minimal schema (no UpdateAppointmentDto:
type: object
properties:
recurringRuleData:
nullable: true
allOf:
- $ref: '#/components/schemas/UpdateRecurringRuleDto'
notes:
type: string
nullable: true
reminderEnabled:
type: boolean
default: falseOn current @JsonKey(includeIfNull: true)
required UpdateRecurringRuleDto? recurringRuleData,
@JsonKey(includeIfNull: true)
required String? notes,
@Default(false)
bool reminderEnabled,With this PR: @Default(false)
bool reminderEnabled,
@JsonKey(includeIfNull: false)
UpdateRecurringRuleDto? recurringRuleData,
@JsonKey(includeIfNull: false)
String? notes,I checked out the PR branch and regenerated our models, and the output above is correct. Both fields are optional again and get omitted from the PATCH body when unset. Properties with We've been carrying this fix in a fork, so we'd be glad to see this merged. Thanks! |
Fixes #460.
For an OpenAPI 3 schema without a
requiredarray, every property was generated asrequiredas soon as any one property usedallOf. Per the spec, a property that is not listed inrequiredis optional, regardless of how its siblings are declared.@nestjs/swaggeremitsallOf: [{ $ref }]for every named enum reference and for nullable DTO references, so a NestJS backend hits this on most request DTOs. In our contract it turned optional fields such asString? fcmTokenintorequired String? fcmToken.The
hasAllOfKeycheck was added in #329, which switched required-ness from "not nullable" to "listed inrequired". It kept the previous output ofNullableUserDtoin theall_of.3.0e2e test (data: allOf [$ref UserDto, {nullable: true}]), not a behavior thatallOfcomposition relies on. Schema-levelallOfcomposition is resolved separately and is unaffected.Changes:
OpenApiParser: removehasAllOfKey, so only therequiredarray anddefaultdecide required-ness.test/parser/all_of_property_not_required_test.dart: schemas without arequiredarray, one with anallOfobject reference and one with a nullableallOfenum reference; asserts every property is optional. Fails without the fix.all_of.3.0e2e expectation:NullableUserDto.databecomes@JsonKey(includeIfNull: false) UserDto? data, the same output as other optional nullable properties.CHANGELOG.md: add a1.45.1entry.pubspec.yamlis left for the release commit, as in Infer nullability from OpenAPI 3.1 type lists when inferring required #472.dart format,dart analyzeand the fulldart testsuite (432 passed, 2 skipped) pass.🤖 Generated with Claude Code