This project intends to output a valid swagger.yaml
or openapi.yaml
file from a Postman collection input.
You can convert:
INPUT | OUTPUT |
---|---|
Postman 2.1 (PostmanCollection.json ) |
Swagger 2.0 (swagger.yaml ) OpenAPI 3.0 ( openapi.yaml ) |
Please Note:
Postman schema doesn't quite match up 1-to-1 against Swagger/OpenAPI schema. So some target spec defaults are automatically implemented when absent in the source spec.
npm install tecfu/postman-to-swagger
Param | Type | Description |
---|---|---|
source_spec | string |
default: "postman2.1". options: "postman2.1" |
target_spec | string |
default: "openapi3.0". options: "swagger2.0", "openapi3.0" |
require_all | array |
default: ["headers", "body", "query", "path"] |
omit | object |
default: { headers: ["Content-Type", "X-Requested-With"] } |
info | object |
default: {} |
responses | object |
default: { 200: { description: "OK" } } |
Param | Type | Description |
---|---|---|
host | string |
default: '' Note: Only applies to Swagger 2.0 output |
basepath | string |
default: '' Note: Only applies to Swagger 2.0 output |
schemes | string |
default: '' Note: Only applies to Swagger 2.0 output |
Param | Type | Description |
---|---|---|
servers | array |
default: [] Note: Only applies to OpenAPI 3.0 output |
const p2s = require('postman-to-swagger')
const yaml = require('js-yaml')
const fs = require('fs')
const postmanJson = require('./postman_collection.json')
const swaggerJson = p2s(postmanJson, {
target_spec: "swagger2.0",
info: {
version: 'v1'
}
})
//let output = JSON.stringify(swaggerJson, null, 2)
let output = yaml.safeDump(swaggerJson)
// Save to file
fs.writeFileSync(
'swagger.yaml',
output,
'utf8'
)