Tag groups (x-tagGroups)
Organize controllers under logical sections in tools that support the x-tagGroups extension, most notably ReDoc.
Declare groups
Pass group and tags to docs():
users.controller.docs.ts
// users.controller.docs.ts
docs(UsersController, {
classDecorators: [ApiTags('users')],
group: 'Administration',
tags: ['users'],
});
// roles.controller.docs.ts
docs(RolesController, {
classDecorators: [ApiTags('roles')],
group: 'Administration',
tags: ['roles'],
});tags must match what you already pass to ApiTags(). nestjs-docfy doesn't call ApiTags for you, it only builds the x-tagGroups mapping from what you declare.
Attach to the document
To actually attach the groups to the generated document, call attachTagGroups() after SwaggerModule.createDocument():
main.ts
// main.ts
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { attachTagGroups } from 'nestjs-docfy';
const config = new DocumentBuilder().setTitle('My API').build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, attachTagGroups(document));Generated extension
yaml
x-tagGroups:
- name: Administration
tags:
- users
- rolesMultiple docs() calls can contribute to the same group: tags are merged and deduplicated. attachTagGroups() is a no-op (returns the document unchanged) when no controller declares a group.