Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selfRequired: false not making an object-type property optional #3347

Merged
merged 2 commits into from
Mar 19, 2025

Conversation

flovouin
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

When using @ApiProperty({ type: 'object', selfRequired: false }) on an object (which is enforced by types, required: false cannot be used on an object as it refers to its own properties), the property is added to the list of required properties. This is a bug.

What is the new behavior?

Setting selfRequired: false on a object-type property does work, and the property is not added to the list of required. This is implemented by having selfRequired taking precedence over required, as selfRequired is non-ambiguous about its intent (it can only be used for object types, with the clear meaning of applying to the decorated property).

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Related to #3163.

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
baev Dmitry Baev

Verified

This commit was signed with the committer’s verified signature.
baev Dmitry Baev
@flovouin flovouin changed the title Fix self required Fix selfRequired: false not making an object-type property optional Mar 17, 2025
@kamilmysliwiec kamilmysliwiec merged commit 8e3cb90 into nestjs:master Mar 19, 2025
1 check passed
@kamilmysliwiec
Copy link
Member

LGTM

@flovouin flovouin deleted the fix-self-required branch March 19, 2025 08:12
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.

None yet

2 participants