feat(swagger): add OpenAPI 3.2 hierarchical tags support#3725
Open
apt-bh wants to merge 1 commit intonestjs:masterfrom
Open
feat(swagger): add OpenAPI 3.2 hierarchical tags support#3725apt-bh wants to merge 1 commit intonestjs:masterfrom
apt-bh wants to merge 1 commit intonestjs:masterfrom
Conversation
Add support for the `parent` and `kind` fields on TagObject as introduced in OpenAPI 3.2. This allows users to organize tags hierarchically for better documentation navigation in large APIs. Changes: - Extend TagObject interface with optional `parent` and `kind` fields - Add new ApiTagOptions type for decorator usage - Extend DocumentBuilder.addTag() to accept hierarchy options - Update @apitags decorator to accept object form alongside strings - Add comprehensive unit and e2e tests Usage: ```typescript // Document-level hierarchy new DocumentBuilder() .addTag('Animals', 'All animal operations') .addTag('Cats', 'Cat operations', undefined, { parent: 'Animals' }) .build(); // Decorator still works with strings (backward compatible) @apitags('Cats') ``` Closes nestjs#3607
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
This PR implements the feature I requested in #3607. I wanted to give it a try myself.
Currently,
TagObjectonly supportsname,description, andexternalDocs. OpenAPI 3.2 introduced hierarchical tags viaparentandkindfields (doc here ), but there's no way to use them with@nestjs/swagger.What is the new behavior?
TagObjectinterface now includes optionalparentandkindfieldsDocumentBuilder.addTag()accepts an optional 4th parameter for hierarchy options@ApiTagsdecorator accepts object form{ name, parent?, kind? }alongside stringsApiTagOptionstype is exported for TypeScript usersNote: The hierarchy info (
parent,kind) is only meaningful at the document level. When using@ApiTagswith objects, thenameis extracted for operation-level tags (which are alwaysstring[]per OpenAPI spec), while the full hierarchy should be defined viaDocumentBuilder.addTag().Does this PR introduce a breaking change?
Other information
OpenAPI version compatibility: The
parentandkindfields are part of the OpenAPI 3.2 specification. Tools that only support OpenAPI 3.0/3.1 will simply ignore these fields, so this feature is fully backward compatible.Closes #3607