![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
openapi-to-postmanv2
Advanced tools
Readme
Supercharge your API workflow. Modern software is built on APIs. Postman helps you develop APIs faster.
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
The converter can be used as a CLI tool as well. The following command line options are available.
openapi2postmanv2 [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
-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
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,includeAuthInfoInExample=false
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -c ./examples/cli-options-config.json
"<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
$ openapi2postmanv2 --test
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:
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..}
}
]
}
*/
}
Check out complete list of options and their usage at OPTIONS.md
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
.
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);
}
}
);
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
{
type: 'object',
properties: {
result: { type: 'boolean'},
reason: { type: 'string' }
},
required: ['result']
}
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
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 |
FAQs
Convert a given OpenAPI specification to Postman Collection v2.0
The npm package openapi-to-postmanv2 receives a total of 41,028 weekly downloads. As such, openapi-to-postmanv2 popularity was classified as popular.
We found that openapi-to-postmanv2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.