An open API service indexing awesome lists of open source software.

https://github.com/tecfu/postman-to-swagger

Convert Postman 2.1 Collections to Swagger 2.0 or OpenAPI 3.0
https://github.com/tecfu/postman-to-swagger

Last synced: about 1 year ago
JSON representation

Convert Postman 2.1 Collections to Swagger 2.0 or OpenAPI 3.0

Awesome Lists containing this project

README

          

# Postman to Swagger

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](https://schema.getpostman.com/json/collection/latest/docs/index.html) (`PostmanCollection.json`) | [Swagger 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) (`swagger.yaml`)

[OpenAPI 3.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md) (`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.

## Installation

```sh
npm install tecfu/postman-to-swagger
```

## Options

### Options: All Targets Specs ```object```

| 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"
}
} |

### Options: Swagger 2.x ```object```

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

### Options: OpenAPI 3.x ```object```

| Param | Type | Description |
| --- | --- | --- |
| servers | array | default: []
Note: Only applies to OpenAPI 3.0 output |

## Example

```js
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'
)
```

## License

[MIT](LICENSE)