2

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

Elrond
  • 479
  • 1
  • 8
  • 21

2 Answers2

6

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'.

Image of Postman Collection Link

See this stackoverflow post for info on how to import it into Postman: Postman JSON Docs Import

Jay
  • 566
  • 6
  • 18
2

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

Hugo Sohm
  • 2,872
  • 4
  • 23
  • 40
  • thanks for your message. Currently I am trying to import the swagger-ui-express version. After the import from api/json in postman nothing is shown there. There are also some errors in the json file: "securitySchemes": { "bearer": { "scheme": "bearer", "bearerFormat": "JWT", "type": "http", "in": "header" } Invalid Properties – Elrond Mar 09 '21 at 15:40
  • The same import is working in Insomnia but not in Postman – Elrond Mar 10 '21 at 06:55
  • Try to import the exported data from Swagger to Insomnia and to export the Insomnia data to Postman, could work as documented [here](https://community.postman.com/t/importing-collection-from-insomnia-v4-as-json-format/9915) – Hugo Sohm Mar 11 '21 at 10:13