Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update Postman collections when new requests get updated by developer to the api

I have my API's document in Swagger which have different endpoints or request. I used the swagger.json link from my API's in Swagger to import them to Postman as collections and then add test cases there.

But I am confused on one thing that if the developers add more requests to the API how can I import the new request without impacting the test cases.

For e.g.:
In one case I have one API with 65 requests that I imported from Swagger UI and test cases written. Then after few days I used the same link to import and number of requests changed to 69 which means 4 new request got added but Postman replaced the whole collection with test cases gone.

like image 879
codingninja Avatar asked Aug 25 '17 14:08

codingninja


1 Answers

As posted in a related question, there is no straightforward solution for now. All you can do now is merging the requests outside of Postman. After all, Postman collections are really just JSON data and can be manipulated as such.

  1. Export your old requests to a collection file 2.0 or newer
  2. Export your new collection the same way
  3. Merge the two JSON files.
  4. Import the new file back to Postman.

I made myself a simple manual helper for step 3 (see the code below), but it can be easily automated in a scripting language of your preference. Steps 1, 2 and 4 can be automated with Newman.

function execute() {
  collection = JSON.parse($(".collection").val());
  swagger = JSON.parse($(".swagger").val());
  result = JSON.stringify($.extend(true, {}, swagger, collection));
  $(".result").val(result);
}
<html><body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <br>Collection: <br> <textarea class="collection"></textarea>
  <br>Swagger: <br> <textarea class="swagger"></textarea>
  <br>Result: <br> <textarea class="result"></textarea>
  <br>
  <button onClick="execute()">EXECUTE</button>
</body></html>
like image 159
Martin Grey Avatar answered Nov 16 '22 23:11

Martin Grey