swagger2postman
Create a Postman collection from Swagger documentation
##Motivation
Swagger UI provides a nice way to interact with an API documented by the Swagger specification.
But if you're working with an identical API across multiple environments, or you want to test edge cases that Swagger UI doesn't support
(like omitting a required query parameter), Swagger UI comes up a bit short.
Postman to the rescue! Using Postman you can define variables for multiple environments and have more control over request generation. This library takes Swagger documentation served in JSON and converts it into a JSON collection which can be imported directly into Postman.
##Demo
Try out an online version at http://app.josephpconley.com/swagger2postman
##Command line
sbt run <host> <collectionName> [<headerKey=headerValue> ... ]
Prints out json and writes json file to current directory.
##Multiple environments
To take advantage of multi-environment testing, I would first run swagger2postman against a hosted Swagger doc.
Then I do a simple Find/Replace, replacing the target host with a handlebars variable like {{host}}
. Then I create environments in Postman that define a value for the config key host
.
Toggling these environments with your imported collection will let you seamlessly test your API in different environments.
You can also use environment variables for authentication. If your API uses a header for authentication, then pass a headerKey
={{headerValue}}
so that all endpoints get a global authentication header with an environment-dependent value.
##Next Steps This currently supports Swagger 1.2. There appears to be Swagger 2.0 import functionality in the current version of Postman, though I haven't gotten it to work, so if there's enough demand for a Swagger 2.0 version, let me know in the issues section (or add it yourself!)