Postman collections are ubiquitous and invaluable for the functional testing of APIs.
However specialized API tests such as API Contract Testing, and API Security Testing require proper OpenAPI Specifications as inputs.
This tools converts Postman collections to full featured OpenAPI v3 Specifications, that enable Codeless Contract Tests
, and Codeless API Security Tests
.
- Install
postman-to-openapi
NPM package
# See https://www.npmjs.com/package postman-to-openapi for details
sudo npm i postman-to-openapi -g
- Install
json-schema
python package
pip install genson
- Generate the OpenAPI YAML
./postman_collection_to_openapi.py <path to the Postman Collection file>
The OpenAPI file will be saved to the same directory as the specified Postman Collection.
- Generate an enriched OpenAPI Specification
./enrich_openapi_spec.py <path to the openapi.yaml file>
The enriched OpenAPI file will be saved to the same directory as the specified
openapi.yaml
.
- Enrichment does the following:
- Split the specification into multiple files based on given prefix
- Add path parameters to the paths if missing
- Replace undefined response status codes with 200
- Remove redundant
content-type
parameters
The ./examples
directory has examples of OpenAPI Specifications generated from Postman Collections (for a couple of well know APIs - GitLab, and GoodBank).