import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; interface ISwaggerSetup { app: any; prefix: string; title?: string; description?: string; version?: string; path?: string; } export const setupSwagger = ({ app, prefix = 'api', title = 'API documents', description = '', version = '1.0', path = '/docs', }: ISwaggerSetup): void => { const config = new DocumentBuilder() .setTitle(title) .setDescription(description) .setVersion(version) .addBearerAuth() // .addApiKey({ type: 'apiKey', name: 'user_id', in: 'header' }, 'user_id') // .addApiKey({ type: 'apiKey', name: 'workspace_id', in: 'header' }, 'workspace_id') // .addApiKey({ type: 'apiKey', name: 'workspace_type', in: 'header' }, 'workspace_type') // .addApiKey({ type: 'apiKey', name: 'authorities', in: 'header' }, 'authorities') .build(); const document = SwaggerModule.createDocument(app, config); // fs.writeFileSync("./swagger-spec.json", JSON.stringify(document)); SwaggerModule.setup(path, app, document); };