I'm using NestJS (v11) and @nestjs/swagger (v11.0.3).
I have a modular app structure where some controllers are intended for public clients (mobile app, frontend) and others are intended for admin dashboard usage.
Problem: When I generate the Swagger documentation using SwaggerModule.createDocument(), it includes all controllers from a module. I want to split Swagger into two separate documents:
/docs → for Public API (client)
/docs-admin → for Admin API
My current swagger setup (main.ts):
.setTitle('API')
.setDescription('API Documentation')
.addServer(`${baseUrl}/${apiPrefix}`)
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, document, {
swaggerOptions: {
search: true,
},
});```
App.module.ts
```@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
CacheModule.register({
isGlobal: true,
}),
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: createTypeOrmConfig,
}),
ApiModule,
],
})
export class AppModule {}```
api.module.ts
```@Module({
imports: [AuthModule, GamesDomainModule, HealthModule, MarketplaceDomainModule],
})
export class ApiModule {}```
marketplace-domain.module.ts
```@Module({
imports: [PerkProvidersModule, PerksModule],
})
export class MarketplaceDomainModule {}```
perks.module.ts
```@Module({
imports: [TypeOrmModule.forFeature([Perk]), PerkProvidersModule],
providers: [PerksService],
controllers: [PerksController, AdminPerksController],
})
export class PerksModule {}```
The problem is that in controllers array I define both PerksController and AdminPerksController. So I cannot just pass in swagger configuration:
`include: [PerksModule]`
What are best approaches here? Should I split modules completely (e.g., create PerksModule and PerksAdminModule) just to separate Swagger documents?