Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including swagger2-to-postmanv2 with all npm packages installed. Try it out:

var swagger2ToPostmanv2 = require("swagger2-to-postmanv2")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

swagger2-to-postmanv2 v0.2.0

A module to convert swagger 2.0 specs to Postman Collection Format v2

swagger2-Postman

Build Status

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: <object>}] Reason must be populated if the result is false. Collection must be populated if result is true.

Conversion Schema

PostmanSwagger2optionsexamples
collectionNameinfo.title--
descriptioninfo.description--
folderNamepaths.path--
requestNamemethod.summary || method.operationId || request.url.raw(in postman)default('operationId') -(requestName) enum[['operationId','summary','url']-
request.methodpath.method (all possible http methods)--
request.headersparams (in = header )-here
request.bodyparams (in = body or formBody)default(true)-(schemaFaker)use json-schema-faker for body conversionhere
request.url.rawscheme(http or https) + '://' + host + basePath--
request.url.paramsparams (in = query)-here
request.url.variablesparams (in = path)-here
Content-Type headerconsumesdefault(true) - add consumes to header-
Accept headerproducesdefault(true) - add produces to header-
apikey in (query or header)securityDefinitions(type = apiKey)--

Header/Query/Path param conversion example

swaggerpostman
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

swaggerpostman
name: role-id
description: role identifier number
in: body
schema: <schemaObject>
"body": {
 "mode": "raw",
 "raw": json-schema-faker(<schemaObject>)
}

If in = formData and consumes = application/x-www-form-urlencoded

swaggerpostman
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

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free