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

Viewed 3228

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.

2 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Ă !

A simple answer to this is to add a line summary: <RequestName>

I came across this problem using the excellent APIs-Gurus OpenAPIDirectory repo

These swagger.yaml files have a operationId: line which can be duplicated and the key replaced with summary: using:

awk '{if (!/      operationId:/) {print ; next} ; { print; a=gensub(/      operationId:/, "      summary:",1) ; print a}}' swagger.yaml  > swagger-new.yaml

Importing this into Postman then shows the correct request name.

PostMan is separating out the Import/Export functions in to separate plug-ins but their plug-in model leaves a lot to be desired at the current time.

Related