I've followed the instructions to create a Swagger documentation, and my documentation is now available using Swagger UI. I'd like to also generate the documentation as JSON or YAML so it's easy to import in e.g. Postman, but I can't find any suitable methods in the SwaggerModule
, nor does the Swagger UI have any export button.
According to this github issue you can just stringify the created Swagger document
and e.g. write it to the file system like this:
const app = await NestFactory.create(ApplicationModule);
const options = new DocumentBuilder()
.setTitle("Title")
.setDescription("description")
.setVersion("1.0")
.build();
const document = SwaggerModule.createDocument(app, options);
fs.writeFileSync("./swagger-spec.json", JSON.stringify(document));
SwaggerModule.setup("/api", app, document);
await app.listen(80);
Try visiting /api/json
instead of /api-json
if you followed https://docs.nestjs.com/recipes/swagger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With