Skip to content

feat(swagger): warn when @ApiTags receives hierarchy fields#3924

Merged
kamilmysliwiec merged 2 commits into
nestjs:masterfrom
frbuceta:feat/api-tags-warn-hierarchy-fields
May 20, 2026
Merged

feat(swagger): warn when @ApiTags receives hierarchy fields#3924
kamilmysliwiec merged 2 commits into
nestjs:masterfrom
frbuceta:feat/api-tags-warn-hierarchy-fields

Conversation

@frbuceta
Copy link
Copy Markdown
Contributor

PR Type

  • Feature
  • Bug fix
  • Other

What is the current behavior?

@ApiTags accepts the object form { name, parent, kind } (added in #3725, released in v11.4.0), but it normalizes every entry to its name, silently discarding parent and kind:

const normalizedTags = tags.map((tag) =>
  typeof tag === 'string' ? tag : tag.name
);

The decorator-level hierarchy metadata never reaches document.tags, so the OpenAPI 3.2 tag hierarchy is lost with no feedback to the user. Root-level tag hierarchy is only honored when declared via DocumentBuilder.addTag(name, description, { parent, kind }).

Issue: #3922

What is the new behavior?

When parent or kind is set on an @ApiTags object argument, the decorator now emits a runtime warning that points users to DocumentBuilder.addTag() — the supported way to define a root-level tag hierarchy.

[ApiTags] Tag "Sessions" was declared with hierarchy fields (parent/kind) on
@ApiTags, which are dropped. Define them via DocumentBuilder.addTag("Sessions",
description, { parent, kind }) so they reach the root-level tags of the document.

This implements the resolution agreed in #3922 ("Reject / warn"). String arguments and object arguments that only carry name are unaffected — no warning is emitted.

Does this PR introduce a breaking change?

  • Yes
  • No

Tag normalization is unchanged; only a diagnostic warning is added.

Other information

Closes #3922. Tests added for the warn / no-warn cases in test/decorators/api-use-tags.decorator.spec.ts.

@apitags accepts the object form { name, parent, kind } but normalizes
each entry to its name, silently discarding parent and kind. The
decorator-level metadata never reaches document.tags, so the OpenAPI 3.2
tag hierarchy is lost without any feedback.

Emit a runtime warning when parent or kind is set on an @apitags object,
pointing users to DocumentBuilder.addTag(), which is the supported way
to define root-level tag hierarchy.

Closes nestjs#3922
Comment thread lib/decorators/api-use-tags.decorator.ts Outdated
@kamilmysliwiec kamilmysliwiec merged commit f797f85 into nestjs:master May 20, 2026
1 check passed
@frbuceta frbuceta deleted the feat/api-tags-warn-hierarchy-fields branch May 20, 2026 09:05
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.

@ApiTags({ name, parent, kind }) silently drops parent and kind

2 participants