Is there a way to import the generated swagger.json to Postman as an collection ?
I tried to import it but the Endpoints are not shown in Postman ?
I am using NestJs and Swagger + Postman
Is there a way to import the generated swagger.json to Postman as an collection ?
I tried to import it but the Endpoints are not shown in Postman ?
I am using NestJs and Swagger + Postman
When setting up your swagger in main.ts (see documentation here: NestJs Swagger Docs) you can add .setExternalDoc('Postman Collection', '/your-api-docs-url-with-the-word-json-at-the-end')
. That gives you a link right at the top of your file so you can click to get the importable JSON.
Here's an example of mine:
const document = SwaggerModule.createDocument(
app,
new DocumentBuilder()
.setTitle('Nest Api')
.setDescription('MyNestApiDescription')
.setVersion('1.0')
.addBearerAuth()
.setExternalDoc('Postman Collection', '/docs-json')
.build(),
);
SwaggerModule.setup('/docs', app, document);
as you can see my API documentation is located at '/docs'
so my json url is simply '/docs-json'
.
See this stackoverflow post for info on how to import it into Postman: Postman JSON Docs Import
You can use fastify-swagger
to export your swagger data using it in Postman after it.
To generate and download a Swagger JSON file, navigate to http://localhost:3000/api-json (swagger-ui-express) or http://localhost:3000/api/json (fastify-swagger) in your browser (assuming that your Swagger documentation is available under http://localhost:3000/api).
More informations about openApi with NestJS is available here