Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@localz/openapi-to-postmanv2

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@localz/openapi-to-postmanv2

Convert a given OpenAPI specification to Postman Collection v2.0

  • 1.2.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25
Maintainers
1
Weekly downloads
 
Created
Source

postman icon

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

OpenAPI 3.0 to Postman Collection v2.1.0 Converter

Build Status

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

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

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 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.
*/

callback:

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

Options:

  • 'schemaFaker'(boolean): whether to use json-schema-faker for schema conversion. Default: true
  • 'requestNameSource'(string): The strategy to use to generate request names. url: use the request's URL as the name, fallback: Use the summary/operationId/URL (in that order) Default: fallback
  • 'indentCharacter' (string): The character to use per level of indentation for JSON/XML data. Default: ' '(space)

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

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

Sample Usage:

var 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

Command Line Interface

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

openapi2postmanv2 [options]

Options

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

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

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

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

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

Usage

Sample usage examples of the converter CLI

  • Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing
$ openapi2postmanv2 -s spec.yaml -o collection.json -p
  • Testing the converter
$ openapi2postmanv2 --test

Conversion Schema

postmanopenapioptionsexamples
collectionNameinfo.title-
descriptioninfo.description + info.contact-
collectionVariablesserver.variables + pathVariables-
folderNamepaths.path-
requestNameoperationItem(method).operationIddefault(operationId)-(requestName)enum['operationId','summary','url']
request.methodpath.method-
request.headersparameter (in = header)-link
request.bodyoperationItem(method).requestBody-
request.url.rawserver.url (path level server >> openapi server) + path-
request.url.variablesparameter (in = path)-link
request.url.paramsparameter (in = query)-{"key": param.name, "value": link}
api_key in (query or header)components.securitySchemes.api_key-

Keywords

FAQs

Package last updated on 09 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc