Skip to content

Conversation

mag123c
Copy link
Contributor

@mag123c mag123c commented Apr 30, 2025

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?

When using @ApiProperty({ enum: SubjectEnum, enumName: 'Subject' }) readonly caslSubjectType: SubjectEnum = this.constructor.name as SubjectEnum;, the generated OpenAPI schema always includes:

"__caslSubjectType__": {
  "default": "Function",
  "allOf": [
    { "$ref": "#/components/schemas/Subject" }
  ]
}

There is no built-in way to omit that default unless you explicitly set default: null.

Issue Number: #3338

What is the new behavior?

Introduce a skipDefaultValues option on the Swagger plugin.

Default: skipDefaultValues: false (existing behavior)

When enabled: any property without an explicit default initializer will not have a default field in the schema.

Example – with skipDefaultValues: true:

@ApiProperty({ enum: SubjectEnum, enumName: 'Subject' })
readonly __caslSubjectType__: SubjectEnum = this.constructor.name as SubjectEnum;
"__caslSubjectType__": {
  "allOf": [
    { "$ref": "#/components/schemas/Subject" }
  ]
}

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Docs will be added upon positive review and merge of this PR.

@kamilmysliwiec kamilmysliwiec merged commit 2646f2b into nestjs:master Apr 30, 2025
1 check passed
@kamilmysliwiec
Copy link
Member

LGTM

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

Successfully merging this pull request may close these issues.

2 participants