• Stars
    star
    918
  • Rank 49,757 (Top 1.0 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Plugin for converting OpenAPI 3.0 specs to the Postman Collection (v2) format

The Postman Logo

Supercharge your API workflow. Modern software is built on APIs. Postman helps you develop APIs faster.

OpenAPI 3.0, 3.1 and Swagger 2.0 to Postman Collection

Build Status

npm npm

Contents

  1. Getting Started
  2. Command Line Interface
    1. Options
    2. Usage
  3. Using the converter as a NodeJS module
    1. Convert Function
    2. Options
    3. ConversionResult
    4. Sample usage
    5. Validate function
  4. Conversion Schema


πŸš€ We now also support OpenAPI 3.1 and Swagger 2.0 along with OpenAPI 3.0.



πŸ’­ Getting Started

To use the converter as a Node module, you need to have a copy of the NodeJS runtime. The easiest way to do this is through npm. If you have NodeJS installed you have npm installed as well.

$ npm install openapi-to-postmanv2

If you want to use the converter in the CLI, install it globally with NPM:

$ npm i -g openapi-to-postmanv2

πŸ“– Command Line Interface

The converter can be used as a CLI tool as well. The following command line options are available.

openapi2postmanv2 [options]

Options

  • -s <source>, --spec <source> Used to specify the OpenAPI specification (file path) which is to be converted

  • -o <destination>, --output <destination> Used to specify the destination file in which the collection is to be written

  • -p, --pretty Used to pretty print the collection object while writing to a file

  • -i, --interface-version Specifies the interface version of the converter to be used. Value can be 'v2' or 'v1'. Default is 'v2'.

  • -O, --options Used to supply options to the converter, for complete options details see here

  • -c, --options-config Used to supply options to the converter through config file, for complete options details see here

  • -t, --test Used to test the collection with an in-built sample specification

  • -v, --version Specifies the version of the converter

  • -h, --help Specifies all the options along with a few usage examples on the terminal

Usage

  • Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,includeAuthInfoInExample=false
  • Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options via config file
$ openapi2postmanv2 -s spec.yaml -o collection.json -p  -c ./examples/cli-options-config.json
  • Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options (Also avoids any "<Error: Too many levels of nesting to fake this schema>" kind of errors present in converted collection)
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,requestParametersResolution=Example,optimizeConversion=false,stackLimit=50
  • Testing the converter
$ openapi2postmanv2 --test

πŸ›  Using the converter as a NodeJS module

In order to use the convert in your node application, you need to import the package using require.

var Converter = require('openapi-to-postmanv2')

The converter provides the following functions:

Convert

The convert function takes in your OpenAPI 3.0, 3.1 and Swagger 2.0 specification ( YAML / JSON ) and converts it to a Postman collection.

Signature: convert (data, options, callback);

data:

{ type: 'file', data: 'filepath' }
OR
{ type: 'string', data: '<entire OpenAPI string - JSON or YAML>' }
OR
{ type: 'json', data: OpenAPI-JS-object }

options:

{
  schemaFaker: true,
  requestNameSource: 'fallback',
  indentCharacter: ' '
}
/*
All three properties are optional. Check the options section below for possible values for each option.
*/

Note: All possible values of options and their usage can be found over here: OPTIONS.md

callback:

function (err, result) {
  /*
  result = {
    result: true,
    output: [
      {
        type: 'collection',
        data: {..collection object..}
      }
    ]
  }
  */
}

Options

Check out complete list of options and their usage at OPTIONS.md

ConversionResult

  • result - Flag responsible for providing a status whether the conversion was successful or not.

  • reason - Provides the reason for an unsuccessful conversion, defined only if result if false.

  • output - Contains an array of Postman objects, each one with a type and data. The only type currently supported is collection.

Sample Usage

const fs = require('fs'),
  Converter = require('openapi-to-postmanv2'),
  openapiData = fs.readFileSync('sample-spec.yaml', {encoding: 'UTF8'});

Converter.convert({ type: 'string', data: openapiData },
  {}, (err, conversionResult) => {
    if (!conversionResult.result) {
      console.log('Could not convert', conversionResult.reason);
    }
    else {
      console.log('The collection object is: ', conversionResult.output[0].data);
    }
  }
);

Validate Function

The validate function is meant to ensure that the data that is being passed to the convert function is a valid JSON object or a valid (YAML/JSON) string.

The validate function is synchronous and returns a status object which conforms to the following schema

Validation object schema

{
  type: 'object',
  properties: {
    result: { type: 'boolean'},
    reason: { type: 'string' }
  },
  required: ['result']
}
Validation object explanation
  • result - true if the data looks like OpenAPI and can be passed to the convert function

  • reason - Provides a reason for an unsuccessful validation of the specification

🧭 Conversion Schema

postman openapi related options
collectionName info.title -
description info.description + info.contact -
collectionVariables server.variables + pathVariables -
folderName paths.path / tags.name folderStrategy
requestName operationItem(method).summary / operationItem(method).operationId / url requestNameSource
request.method path.method -
request.headers parameter (in = header) -
request.body operationItem(method).requestBody requestParametersResolution, exampleParametersResolution
request.url.raw server.url (path level server >> openapi server) + path -
request.url.variables parameter (in = path) -
request.url.params parameter (in = query) -
api_key in (query or header) components.securitySchemes.api_key includeAuthInfoInExample

More Repositories

1

httpbin

HTTP Request & Response Service, written in Python + Flask.
Python
12,664
star
2

newman

Newman is a command-line collection runner for Postman
JavaScript
6,859
star
3

postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIsβ€”faster.
5,826
star
4

postman-code-generators

Common repository for all code generators shipped with Postman
JavaScript
991
star
5

postman-docs

Documentation for Postman, a collaboration platform for API development. Available for Mac, Windows, and Linux.
JavaScript
559
star
6

postman-collection

Javascript module that allows a developer to work with Postman Collections
JavaScript
456
star
7

postman-runtime

JavaScript
238
star
8

postman-chrome-interceptor

Helper extension for the Postman packaged app. Also helps send restricted headers.
JavaScript
207
star
9

covid-19-apis

Postman COVID-19 API Resource Centerβ€”API collections to help in the COVID-19 fight.
JavaScript
127
star
10

npm-cli-login

JavaScript
113
star
11

swagger2-to-postman

Converter for swagger 2.0 JSON to Postman Collection
JavaScript
113
star
12

postman-sandbox

Sandbox for Postman Scripts to run in Node.js or browser
JavaScript
104
star
13

postman-chrome-extension-legacy

Postman REST Client Chrome Extension (Legacy Version)
JavaScript
94
star
14

postman-collection-transformer

Perform rapid conversion and validation of JSON structure between Postman Collection Format v1 and v2.
JavaScript
87
star
15

postman-flows

We're maintaining this repo to share the progress of Flows publicly and get feedback at the same time.
86
star
16

newman-docker

Docker images for Newman Collection Runner
Shell
80
star
17

swagger2-postman2

Module and library to convert Swagger 2.0 to a Postman Collection (v2.0)
JavaScript
79
star
18

newman-reporter-html

HTML
76
star
19

curl-to-postman

Converts curl requests to Postman Collection v2 request objects
JavaScript
62
star
20

sails-mysql-transactions

sails/waterline ORM with mySQL transaction support
JavaScript
58
star
21

uvm

Universal Virtual Machine for Node and Browser
JavaScript
40
star
22

schemas

Repository of all schemas for JSON structures compatible with Postman (such as the Postman Collection Format)
JavaScript
38
star
23

postman-updater-linux

A simple bash script to update Postman from the command line (for Linux)
Shell
35
star
24

graphql-to-postman

Plugin for converting GraphQL to the Postman Collection (v2) format
JavaScript
34
star
25

gsoc

Postman - Google Summer of Code
32
star
26

node-doc-kube

🐱 URL shortener using cat verbs, cat adjectives, and cat emojis
JavaScript
31
star
27

chai-postman

Chai plugin to assert on Postman Collections
JavaScript
28
star
28

postman-collection-code-generators

Repository for generating code from Postman Collection
JavaScript
22
star
29

postman

21
star
30

e-commerce-store-express

JavaScript
20
star
31

newman-dashboard

A WebUI companion for Newman to control, view and debug runs. πŸš€βœ¨
JavaScript
18
star
32

raml2postman

Coverts RAML specs to Postman Collections (v1 of the collection format)
JavaScript
18
star
33

postman-url-encoder

Implements URL encoding according to the WHATWG specification
JavaScript
18
star
34

runscope-to-postman

Convert Runscope Radar Tests to Postman Collection v2
JavaScript
14
star
35

postman-jsdoc-theme

A JSDoc Theme
JavaScript
13
star
36

wsdl-to-postman

Enables Postman support of the WSDL specification
JavaScript
13
star
37

uniscope

Evaluate a code within a controlled environment
JavaScript
12
star
38

env-lift

Simple namespaced environment variable configuration management solution
JavaScript
12
star
39

templates

11
star
40

spectral-postman

A sample API that retrieves constellations as an example to demonstrate features in the OpenAPI 3.0 specification.
Shell
11
star
41

devrel-content

Project to track content creation requests and progress for the Postman Developer Relations team.
10
star
42

api-spec-converter

JavaScript
10
star
43

raml1-to-postman

Converter for RAML1.0 specs to Postman v2 collections
JavaScript
10
star
44

http-reasons

Database to lookup http reasons from http response status code
JavaScript
9
star
45

generic-bitmask

Module to compute and manipulate bitmasks in JavaScript
JavaScript
9
star
46

postman-zendesk-support-theme

Zendesk v2 API theme support for Postman Support Center
Handlebars
8
star
47

letsencrypt-manager

JavaScript
7
star
48

swagger2-postman2-lambda

JavaScript
7
star
49

postmanlabs.github.io

Content for the laboratory website!
HTML
7
star
50

open-technologies-docs

Open Technology Documentation
JavaScript
6
star
51

postman-blog

JavaScript
6
star
52

intergalactic-apifirst

6
star
53

newman-reporter-remote

JavaScript
6
star
54

labs-docs

JavaScript
6
star
55

sails-hook-rewire

Installable sailsjs hook that lets you rewire sails components during tests
JavaScript
5
star
56

codegen-curl

curl snippet generator for Postman Requests
JavaScript
5
star
57

liquid-json

Implementation of JSON that ignores BOM and thows friendly error
JavaScript
5
star
58

uptime-monitors

5
star
59

galaxy-workshop

Supporting resources for the 2020 Postman Galaxy Tour
5
star
60

dhc-to-postman

Converts a DHC Project to a Postman Collection (v1)
JavaScript
5
star
61

postman-badge-checker

Used for checking and awarding Postman badges
5
star
62

node-oauth1

An implementation of OAuth1 signature generation
JavaScript
4
star
63

postman-api-environments-utils

Utilities to manage Postman environments using the Postman API.
JavaScript
4
star
64

postman-japanese-ea

Issue tracking for the Postman App Japanese Early Access release
4
star
65

serialised-error

Serialises error object to normal object
JavaScript
4
star
66

swagger1-to-postman

JavaScript
3
star
67

schema-compiler

json-schema-builder
JavaScript
3
star
68

sails-hook-responders

An installable sailsjs hook that adds policies, called responders, to a request
JavaScript
3
star
69

postman-validator

JavaScript
3
star
70

.github

3
star
71

learning-resources

3
star
72

postman-sdk-go

Go SDK powering Live Collections
Go
3
star
73

execute-postman-monitor

GitHub action that executes a Postman Monitor.
JavaScript
3
star
74

newman-orb

CircleCI Orb for running collections with Newman - https://circleci.com/orbs/registry/orb/postman/newman
3
star
75

async-domino

A module to allow time guaranteed asynchronous functions
JavaScript
3
star
76

har-to-postman

JavaScript
3
star
77

save-as-postman-request

Command line utility to process piped curl responses and create postman a request on a collection using the Postman API
JavaScript
3
star
78

solutions

Useful learning resources, scripts, videos, snippets and materials etc. collated by the Solutions Engineering team at Postman.
2
star
79

postman-learning

Postman and API Development
2
star
80

gists

2
star
81

examples

2
star
82

intergalactic-ice-cream

2
star
83

ical-json

JSON representation of calendar entries (with cron compatibility)
JavaScript
2
star
84

mime-format

Database to mime-format based on content-type header and content
JavaScript
2
star
85

pratishat

Percent-encode specific characters in the string
JavaScript
2
star
86

push-openapi-to-postman

Github action that pushes an OpenAPI in the repository to a specific API in a Postman workspace, creating a new version.
JavaScript
2
star
87

sails-env-switch

JavaScript
2
star
88

postman-mock-servers

1
star
89

raml-to-postman

RAML
1
star
90

packity

Sanity check of installed packages as per package.json
JavaScript
1
star
91

livestream-content

Content used and shared on Livestream events
Python
1
star
92

eslint-config-postman

Common ESLint rules for Postman! πŸ‘•
JavaScript
1
star
93

orbit-actions

1
star
94

collection-format-docs

Documentation for postman collection format, the open source specification that powers collections in postman
JavaScript
1
star
95

postman-collection-spectral-linter

Utility to lint and validate the quality of a Postman collection
JavaScript
1
star