Skip to content

fix(schema): include type field when nullable is used with allOf#3784

Merged
kamilmysliwiec merged 2 commits into
nestjs:masterfrom
maruthang:fix/nullable-type-field-3274
Apr 15, 2026
Merged

fix(schema): include type field when nullable is used with allOf#3784
kamilmysliwiec merged 2 commits into
nestjs:masterfrom
maruthang:fix/nullable-type-field-3274

Conversation

@maruthang

Copy link
Copy Markdown
Contributor

PR Checklist

  • The commit message follows our guidelines
  • Tests for the changes have been added
  • Docs have been added / updated

PR Type

  • Bugfix

What is the current behavior?

When a property is UserDto | null, the schema has nullable: true and allOf: [{ $ref }] but no type field. Redocly's linter errors: "The type field must be defined when the nullable field is used."

Issue Number: #3274

What is the new behavior?

Preserves type: 'object' for nullable properties with schema combinators. The extractPropertiesFromType combinator handler now keeps type when nullable: true.

Does this PR introduce a breaking change?

  • No

When a property is nullable with a $ref (e.g. UserDto | null),
the schema had nullable: true and allOf but no type field. This
caused Redocly lint errors since OpenAPI 3.0 requires type when
nullable is present. Now preserves type: 'object' for nullable
properties with schema combinators.

Closes nestjs#3274
@kamilmysliwiec

Copy link
Copy Markdown
Member

Could you add an e2e test?

@maruthang

Copy link
Copy Markdown
Contributor Author

Hi @kamilmysliwiec, e2e test added! It adds a nullableTag property to CreateCatDto with @ApiProperty({ nullable: true, type: () => TagDto }) and asserts the generated schema includes type: 'object' alongside nullable: true and allOf. All 103 e2e tests pass.

@kamilmysliwiec kamilmysliwiec merged commit b0f01d5 into nestjs:master Apr 15, 2026
1 check passed
@kamilmysliwiec

Copy link
Copy Markdown
Member

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants