Convert OpenAPI 3.0 and OpenAPI / Swagger 2.0 Specs to Postman 2.0 Collections. Example RingCentral spec included.
Spectrum is a multi-purpose OpenAPI Spec SDK that includes enhanced Postman conversion. Most of the OpenAPI Spec SDK is designed to support OAS3. Some functionality for OAS2 exists.
The following article provides an overview of OpenAPI spec to Postman conversion:
x-tagGroups
are converted to Postman folders.https://{{HOSTNAME}}/restapi
Authorization: Bearer {{myAccessToken}}
prerequest
scripts.description
and summary
from description
and displayName
respectively.request.url
property can be populated by a URL string or a URL object. Spectrum uses the URL object since it is more flexible. The function simple.NewCanonicalCollectionFromBytes(bytes)
can be used to read either a simple or object based spec into a canonical object spec.examples
folder.The following command will install the executable binary spectrum
into the ~/go/bin
directory.
$ go get github.com/grokify/spectrum
// Instantiate a converter with default configuration
conv := spectrum.NewConverter(spectrum.Configuration{})
// Convert a Swagger spec
err := conv.Convert("path/to/swagger.json", "path/to/pman.out.json")
The following can be added which are especially useful to use with environment variables.
// Instantiate a converter with overrides (using Postman environment variables)
cfg := spectrum.Configuration{
PostmanURLBase: "{{RINGCENTRAL_SERVER_URL}}",
PostmanHeaders: []postman2.Header{
{
Key: "Authorization",
Value: "Bearer {{my_access_token}}",
},
},
}
conv = spectrum.NewConverter(cfg)
// Convert a Swagger spec with a default Postman spec
err := conv.MergeConvert("path/to/swagger.json", "path/to/pman.base.json", "path/to/pman.out.json")
An example conversion is included, examples/ringcentral/convert.go
which creates a Postman 2.0 spec for the RingCentral REST API using a base Postman 2.0 spec and the RingCentral basic Swagger 2.0 spec.
A video of importing the resulting Postman collection is available on YouTube.
Example files include:
The RingCentral spec uses the following environment variables. The following is the Postman bulk edit format:
RC_SERVER_HOSTNAME:platform.devtest.ringcentral.com
RC_APP_KEY:myAppKey
RC_APP_SECRET:myAppSecret
RC_USERNAME:myMainCompanyPhoneNumber
RC_EXTENSION:myExtension
RC_PASSWORD:myPassword
For multiple apps or users, simply create a different Postman environment for each.
To set your environment variables, use the Settings Gear icon and then click “Manage Environments”