Install
To use local in your Node.js project as a library
npm i postman-to-openapi --save
To use as a cli
npm i postman-to-openapi -g
Usage
As library
Use the library is as easy as use a single method async postmanToOpenApi(input, outputPath, options)
, the parameters are:
Param | Description |
---|---|
input | String. Path of the Postman collection file or value of the postman collection as String. |
outputPath | String. Path of the output file where the OpenAPi will be stored. This param is optional if not provided (undefined or null ) no file will be saved. |
options | Object. Optional configuration, see options section for a detailed description. |
The method return a promise string that contain the yml OpenAPI specification, only is saved to a file if the outputPath
parameter is provided.
An example of usage:
const postmanToOpenApi = require('postman-to-openapi');
const postmanCollection = './path/to/postman/collection.json';
const outputFile = './api/collection.yaml';
// Async/await
try {
// Without save the result in a file
const result = await postmanToOpenApi(postmanCollection, null, { defaultTag: 'General' })
console.log(`OpenAPI specs: ${result}`)
} catch (err) {
console.log(err)
}
// Promise callback style
// With save the result in a file
postmanToOpenApi(postmanCollection, outputFile, { defaultTag: 'General' })
.then(result => {
console.log(`OpenAPI specs: ${result}`)
})
.catch(err => {
console.log(err)
})
As cli
After install just need to
p2o ./path/to/PostmantoCollection.json -f ./path/to/result.yml -o ./path/to/options.json
All the field described in options can be provided and used in the cli, for more info an all the available options just check the cli help
p2o -h
See demo in next gif:

Options
The third parameter used in the library method is an options
object containing the optional parameters for the transformation, the allowed parameters are:
Param | Description |
---|---|
info | Basic API information |
defaultTag | Values of the default tag object. |
pathDepth | Number of subpaths that should be part of the operation path. |
auth | Global authorization definition object. |
servers | Server list for the OpenApi specs. |
externalDocs | Info about the API external documentation. |
folders | Config object for folders and nested folders in postman collection. |
responseHeaders | Indicate if should parse the response headers from the collection examples. |
replaceVars | Boolean value to indicate if postman variables should be replaced. |
additionalVars | Object to provide additional values for variables replacement. |