Skip to content

fix(decorators): forward all OpenAPI parameter fields in @ApiHeader#3870

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
yogeshwaran-c:fix/api-header-forward-all-fields
Apr 22, 2026
Merged

fix(decorators): forward all OpenAPI parameter fields in @ApiHeader#3870
kamilmysliwiec merged 1 commit intonestjs:masterfrom
yogeshwaran-c:fix/api-header-forward-all-fields

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

@ApiHeader only forwarded description, required, examples and schema onto the generated parameter metadata. The remaining OpenAPI Parameter Object fields it advertises via ApiHeaderOptions extends Omit<ParameterObject, 'in'>deprecated, allowEmptyValue, style, explode, allowReserved, content — were silently dropped.

Minimal repro:

@ApiHeader({
  name: 'X-API-Version',
  deprecated: true,
  allowEmptyValue: true,
  style: 'simple',
  explode: false,
  allowReserved: true,
})
@Get()
find() {}

None of the flagged flags appear on the emitted parameter. A content-only header additionally ended up with an unwanted synthetic schema: { type: 'string' }, which is invalid per OpenAPI (schema and content are mutually exclusive on a Parameter Object).

What is the new behavior?

  • All fields defined on BaseParameterObject (deprecated, allowEmptyValue, style, explode, allowReserved, content) are now forwarded into the parameter metadata.
  • When the caller supplies content, the default schema: { type: 'string' } is suppressed so the emitted parameter only carries content, matching the spec's mutual-exclusivity rule.
  • Behaviour for existing callers is unchanged: the default schema: { type: 'string' } and the top-level example mapping to schema.example both still apply when no content is provided.

Additional context

Added a dedicated test/decorators/api-header.decorator.spec.ts with four regressions (simple header, fully-populated header, content-only header, top-level example). The existing swagger-explorer when headers are defined suite continues to pass untouched.

ApiHeader only propagated `description`, `required`, `examples` and
`schema` onto the generated parameter metadata, silently dropping the
other OpenAPI parameter fields defined on BaseParameterObject:
`deprecated`, `allowEmptyValue`, `style`, `explode`, `allowReserved`
and `content`. Users passing these options saw them disappear from
the generated OpenAPI document with no warning.

Forward the missing fields through to the parameter metadata so they
reach the explorer. Also avoid emitting the synthetic
`schema: { type: 'string' }` when the caller has supplied `content`,
since `schema` and `content` are mutually exclusive per the OpenAPI
Parameter Object spec.
@kamilmysliwiec kamilmysliwiec merged commit 8fb869c into nestjs:master Apr 22, 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