Skip to content

Commit 9eaa0e7

Browse files
Merge pull request #3435 from frbuceta/docs/openapi-32-hierarchical-tags
docs(openapi): document OpenAPI 3.2 hierarchical tags
2 parents 8664a9b + 9a1da2f commit 9eaa0e7

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

content/openapi/operations.md

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

15+
16+
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()`:
17+
18+
```typescript
19+
const config = new DocumentBuilder()
20+
.setOpenAPIVersion('3.2.0')
21+
.addTag('Animals', 'Everything about animals', undefined, { kind: 'nav' })
22+
.addTag('Cats', 'Cat operations', undefined, { parent: 'Animals' })
23+
.addTag('Dogs', 'Dog operations', undefined, { parent: 'Animals' })
24+
.build();
25+
```
26+
27+
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`.
28+
29+
> 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.
30+
1531
#### Headers
1632

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

0 commit comments

Comments
 (0)