Skip to content

fix(swagger): type Tag Object kind as a free-form string#3925

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
frbuceta:fix/tag-kind-free-form-string
May 20, 2026
Merged

fix(swagger): type Tag Object kind as a free-form string#3925
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
frbuceta:fix/tag-kind-free-form-string

Conversation

@frbuceta

Copy link
Copy Markdown
Contributor

PR Type

  • Bug fix
  • Feature
  • Other

What is the current behavior?

TagObject.kind, ApiTagOptions.kind and the DocumentBuilder.addTag() options.kind parameter are all typed as:

kind?: 'navigation' | 'reference';

This closed union was introduced in #3725 (v11.4.0). However, the OpenAPI 3.2 Tag Object defines kind as a machine-readable, free-form string. The spec lists only nav, badge and audience as conventional values, and explicitly does not mandate them.

As a result the current type:

  • rejects every conventional value the spec actually names (nav, badge, audience);
  • offers two values (navigation, reference) that do not appear in the spec at all;
  • rejects any custom/vendor value, even though the spec permits free-form text.
// rejected today, valid per OpenAPI 3.2:
builder.addTag('Cats', '', undefined, { kind: 'nav' });

Spec references: OpenAPI 3.2 Tag Object, learn.openapis.org — Enhanced Tags.

What is the new behavior?

kind is widened to string on TagObject, ApiTagOptions and DocumentBuilder.addTag(), with a JSDoc note pointing to the conventional values (nav, badge, audience). Any spec-conventional or custom value is now accepted.

Does this PR introduce a breaking change?

  • Yes
  • No

The type is widened, not narrowed — every value that compiled before still compiles. Existing addTag tests were updated to use spec-conventional values, and a test for a free-form custom value was added.

Other information

Part of the OpenAPI 3.2 tag-hierarchy support added in #3725.

The OpenAPI 3.2 Tag Object defines `kind` as a machine-readable,
free-form string; the spec only lists `nav`, `badge` and `audience`
as conventional values, none of which are mandated.

The type was `'navigation' | 'reference'`, a closed union of two
values that do not appear in the spec. This rejects every conventional
value and any custom one a user might choose.

Widen `kind` to `string` on `TagObject`, `ApiTagOptions` and the
`DocumentBuilder.addTag()` options, with a JSDoc note pointing to the
conventional values.
@kamilmysliwiec kamilmysliwiec merged commit 0a1d9c1 into nestjs:master May 20, 2026
1 check passed
@frbuceta frbuceta deleted the fix/tag-kind-free-form-string branch May 20, 2026 09:04
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