https://github.com/postmanlabs/swagger2-postman2
Module and library to convert Swagger 2.0 to a Postman Collection (v2.0)
https://github.com/postmanlabs/swagger2-postman2
Last synced: 9 months ago
JSON representation
Module and library to convert Swagger 2.0 to a Postman Collection (v2.0)
- Host: GitHub
- URL: https://github.com/postmanlabs/swagger2-postman2
- Owner: postmanlabs
- License: apache-2.0
- Created: 2018-03-01T15:11:37.000Z (almost 8 years ago)
- Default Branch: develop
- Last Pushed: 2023-07-19T02:33:13.000Z (over 2 years ago)
- Last Synced: 2025-03-28T23:06:29.688Z (10 months ago)
- Language: JavaScript
- Size: 8.53 MB
- Stars: 82
- Watchers: 10
- Forks: 39
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# swagger2-Postman
[](https://travis-ci.com/postmanlabs/swagger2-postman2)
Converter for swagger 2.0 JSON to Postman Collection v2
Exports the following functions:
* validate(JSON-or-string)*: Formats like RAML/cURL don't have a JSON representation. For others, JSON is preferred. The result should be an object: `{result: true/false, reason: 'string'}`. Reason must be populated if the result is false. This function will be used by the app to determine whether or not this converter can be used for the given input.
* convert(JSON-or-string)*: Converts the input to a collection object. Conversion result should be an object: `{result: true/false, reason: '', output:[{type: 'collection', data: }]` Reason must be populated if the result is false. Collection must be populated if result is true.
# Conversion Schema
| *Postman* | *Swagger2* | options | examples |
| --- | --- | :---: | :---: |
| collectionName | info.title | - | - |
| description | info.description | - | - |
| folderName | paths.path | - | - |
| requestName| method.summary \|\| method.operationId \|\| request.url.raw(in postman) | default('operationId') -(`requestName`) enum[['operationId','summary','url'] | - |
| request.method | path.method (`all possible http methods`) | - | - |
| request.headers | params (`in = header` ) | - |here|
| request.body | params (`in = body or formBody`) | default(true)-(`schemaFaker`)use json-schema-faker for body conversion | here |
| request.url.raw | scheme(http or https) + '://' + host + basePath | - | - |
| request.url.params | params (`in = query`)| - | here |
| request.url.variables | params (`in = path`) | - | here |
| Content-Type header | consumes | default(true) - add consumes to header | - |
| Accept header | produces | default(true) - add produces to header | - |
| apikey in (query or header) | securityDefinitions(`type = apiKey`) | - | - |
### Header/Query/Path param conversion example
| swagger | postman |
| --- | --- |
| name: api-key
description: session token
in: header
type: integer
default: defaultValue |{
"key": "api-key",
"value": defaultValue,
"description": "session token"
}|
### Body param conversion example
#### If `in = body`
| swagger | postman |
| --- | --- |
|name: role-id
description: role identifier number
in: body
schema: \|"body": {
"mode": "raw",
"raw": json-schema-faker(\)
}|
#### If `in = formData` and `consumes = application/x-www-form-urlencoded`
| swagger | postman |
| --- | --- |
|name: role-id
description: role identifier number
in: formData
default: defaultValue|"body": {
"mode": "urlencoded",
"urlencoded": [{
"key": "role-id",
"value": defaultValue,
"type": "text",
}]
}|
> All parmas with above condition are added to urlencoded array.
#### If `in = formData` and `consumes = multipart/form-data`
| swagger | postman |
| --- | --- |
|name: role-id
description: role identifier number
in: formData
default: defaultValue|"body": {
"mode": "formdata",
"formdata": [{
"key": "role-id",
"value": defaultValue,
"type": "text",
}]
}|
> All parmas with above condition are added to formdata array.