Skip to content

Commit 4c7f327

Browse files
committed
docs(openapi): document OpenAPI 3.2 hierarchical tags
Add a 'Hierarchical tags' subsection to the Operations > Tags page covering the parent and kind options on DocumentBuilder.addTag(). Notes that setOpenAPIVersion('3.2.0') must be called so the generated document declares a 3.2-compatible openapi version; otherwise it still reports 3.0.0 and strict validators reject the new tag fields. Closes nestjs/swagger#3926
1 parent 8664a9b commit 4c7f327

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

content/openapi/operations.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ To attach a controller to a specific tag, use the `@ApiTags(...tags)` decorator.
1212
export class CatsController {}
1313
```
1414

15+
##### Hierarchical tags
16+
17+
OpenAPI 3.2 extends the Tag Object so that tags can be organized into a hierarchy and annotated with a hint about how they should be presented. To declare these relationships, define the tags up front with `DocumentBuilder` and pass the `parent` and `kind` options to `addTag()`:
18+
19+
```typescript
20+
const config = new DocumentBuilder()
21+
.setOpenAPIVersion('3.2.0')
22+
.addTag('Animals', 'Everything about animals', undefined, { kind: 'nav' })
23+
.addTag('Cats', 'Cat operations', undefined, { parent: 'Animals' })
24+
.addTag('Dogs', 'Dog operations', undefined, { parent: 'Animals' })
25+
.build();
26+
```
27+
28+
The `parent` option references another tag by name, and `kind` is a free-form, machine-readable string that hints how the tag should be used — commonly `nav`, `badge`, or `audience`.
29+
30+
> warning **Warning** The `parent` and `kind` fields belong to the OpenAPI 3.2 Tag Object. You must call `setOpenAPIVersion('3.2.0')`, otherwise the generated document still declares `openapi: 3.0.0` and strict validators will reject these fields. Hierarchy fields can only be defined through `DocumentBuilder.addTag()`; setting them on the `@ApiTags()` decorator has no effect.
31+
1532
#### Headers
1633

1734
To define custom headers that are expected as part of the request, use `@ApiHeader()`.

0 commit comments

Comments
 (0)