Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I import Swagger API to Postman, all request names end up blank in Postman GUI

I am QA engineer. The Dev team produces documentation for our product's RESTful API using Swagger. I need to import this to Postman to make it easy to invoke the product's API.

After importing the JSON file (in Swagger format) into Postman, there is 1 but big problem: All titles (and descriptions) of individual requests are blank! (see screen shot below).

enter image description here

Apparently, this is a known issue, documented here: https://github.com/postmanlabs/postman-app-support/issues/1434

We have literally hundreds of requests. I need to find a sufficiently effective yet simple way to ensure all request titles in Postman are populated with a value which I would like to calculate on the fly.

I have been considering the following approach:

Write a command line tool (using NodeJS or another solid platform) which will receive: 1. ID of the collection to fix 2. api key

It will iterate through all requests in the collection. For each request: if Name field is blank, then a substring of the request URL will be assigned to the Name field; if name is not blank, the request is left alone.

What I am unsure about:

  1. Can I do this programmatically from Postman? It does not make sense to put this code into any one individual request (as pre or post).

(If I have to code this util outside of Postman)

  1. For NodeJS there are "postman-collection" and "postman-sdk" but I am slightly confused which I should use.

  2. Unfortunately, I have not yet found any suitable > library for maintaining Postman collections using C# > or Java.

I am quite frankly confused by the available options. Any guidance will be appreciated.

like image 988
onTy Avatar asked Nov 04 '18 15:11

onTy


People also ask

Can we Import swagger to Postman?

Importing Link. If we have the Swagger-UI link, we can directly use the link to import the API into Postman.


1 Answers

I had the same problem, solved it thanks to Ian T Price solution (just copy operationId value into a new key summary). I decided to write a little javascript utility for this:

function swagPostman(swaggerJson) {
  for (let path in swaggerJson.paths) {
    let methods = ["get", "head", "post", "put", "delete", "connect", "options", "trace", "patch"];

    methods.map(method => {
      if ((swaggerJson.paths[path] || {})[method]) {
        swaggerJson.paths[path][method].summary =
          swaggerJson.paths[path][method].operationId;
      }
    });
  }

  return JSON.stringify(swaggerJson);
}

Also made a simple pen where to run the script with a GUI: https://codepen.io/0x616c65/full/pMaQpb. You just copy-paste your swagger.json file in that pen and woilà!

like image 104
0x01 Avatar answered Sep 28 '22 08:09

0x01