Skip to content

Convert Postman Collections to Full OpenAPI V3 Specifications

License

Notifications You must be signed in to change notification settings

levoai/postman-to-openapi

Repository files navigation

Postman to OpenAPI

Postman-to-OpenAPI

Synopsis

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.

Usage

  1. Install postman-to-openapi NPM package
# See https://www.npmjs.com/package postman-to-openapi for details
sudo npm i postman-to-openapi -g
  1. Install json-schema python package
pip install genson
  1. 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.

  1. 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

Examples

The ./examples directory has examples of OpenAPI Specifications generated from Postman Collections (for a couple of well know APIs - GitLab, and GoodBank).