Swagger UI
The swagger module is unlike most other Nest.js modules. Instead of being imported into your application’s primary app module, the swagger module is configured within the main bootstrap of your application.
async
function
bootstrap() {
const
app
=
await
NestFactory
.
create
(
AppModule
);
const
document
=
SwaggerModule
.
createDocument
(
app
,
swaggerOptions
);
SwaggerModule
.
setup
(
'/swagger'
,
app
,
document
);
await
app
.
listen
(
process
.
env
.
PORT
||
3000
);
}
After declaring the Nest application and before calling the listen
method, we use the swagger document options configured in the last section and SwaggerModule.createDocument
to create the swagger document. The swagger module will inspect all controllers within the application and use decorators to construct the swagger document in memory.
Once we have created the swagger document, we setup and instruct the swagger module to serve the swagger UI at a specified path, SwaggerModule.setup('/swagger...