Swagger
Introduction
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"plugins": ["@nestjs/swagger/plugin"]
}
}export const initializeSwaggerDoc = (app: INestApplication) => {
const contextPath = process.env.CONTEXT_PATH || 'v1';
app.setGlobalPrefix(contextPath);
const config = new DocumentBuilder()
.setTitle('Test API')
.setDescription('Draft version')
.setVersion('1.0')
// .addServer(process.env.BACKEND_ENV)
.setBasePath(contextPath)
.build();
const options: SwaggerDocumentOptions = {
include: [AppModule],
deepScanRoutes: true,
operationIdFactory: (controllerKey: string, methodKey: string) => methodKey,
};
const documentFactory = SwaggerModule.createDocument(app, config, options);
// The ui will be generated on /v1/open-api
// The open api spec will be generated on /v1/open-api-json
SwaggerModule.setup(`${contextPath}/open-api`, app, documentFactory, {
swaggerOptions: {
tagsSorter: 'alpha',
operationsSorter: 'alpha',
},
});
};Api Property
Api Response
Last updated