Skip to content

Commit a23040f

Browse files
committed
Merge branch 'release/4.5.0'
2 parents e8fb2ab + f2cae8f commit a23040f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4967
-276
lines changed

.github/workflows/integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
node-version: '14.x'
1414
- run: npm install
1515
- run: npm run test-lint
16+
- run: npm run test-system
1617
- run: npm run test-unit
1718

1819
Regression:

.travis.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# OpenAPI-Postman Changelog
22

3+
#### v4.5.0 (December 23, 2022)
4+
* Fixed issue [#11519](https://github.com/postmanlabs/postman-app-support/issues/11519) Collection generated from imported OpenAPI were missing certain properties.
5+
* Fixed issue [#11227](https://github.com/postmanlabs/postman-app-support/issues/11227) Collection generated produces incorrect XML requests and responses from Open API 3.0 and Swagger 2.0 API definitions.
6+
* Fixed issue [#11527](https://github.com/postmanlabs/postman-app-support/issues/11527) where generated collection contained empty body when */* was used as content-type.
7+
* Fixed issue [#626](https://github.com/postmanlabs/openapi-to-postman/issues/626) - Add a new option (includeDeprecated) to handle deprecated properties (operations, parameters, or schema properties).
8+
* Fixed issue [#643](https://github.com/postmanlabs/openapi-to-postman/issues/643) Generated value for corresponding authorization should be an environment value.
9+
* Removed travis workflows as GitHub actions are present now.
10+
* Updated README.md to include Swagger 2.0 and OpenAPI 3.1 support.
11+
* Updated README.md to include new postman logo.
12+
313
#### v4.4.0 (November 29, 2022)
414
* Fixed issue where collection folder name for paths were having extra spaces.
515
* Fixed issue where pipelines were failing for certain node version.

OPTIONS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ requestParametersResolution|enum|Example, Schema|Schema|Select whether to genera
88
exampleParametersResolution|enum|Example, Schema|Example|Select whether to generate the response parameters based on the [schema](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject) or the [example](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#exampleObject) in the schema.|CONVERSION
99
folderStrategy|enum|Paths, Tags|Paths|Select whether to create folders according to the spec’s paths or tags.|CONVERSION
1010
schemaFaker|boolean|-|true|Whether or not schemas should be faked.|CONVERSION
11-
stackLimit|integer|-|10|Number of nesting limit till which schema resolution will happen. Increasing this limit may result in more time to convert collection depending on complexity of specification. (To make sure this option works correctly "optimizeConversion" option needs to be disabled)|CONVERSION
11+
stackLimit|integer|-|8|Number of nesting limit till which schema resolution will happen. Increasing this limit may result in more time to convert collection depending on complexity of specification. (To make sure this option works correctly "optimizeConversion" option needs to be disabled)|CONVERSION
1212
includeAuthInfoInExample|boolean|-|true|Select whether to include authentication parameters in the example request|CONVERSION
1313
shortValidationErrors|boolean|-|false|Whether detailed error messages are required for request <> schema validation operations.|VALIDATION
1414
validationPropertiesToIgnore|array|-|[]|Specific properties (parts of a request/response pair) to ignore during validation. Must be sent as an array of strings. Valid inputs in the array: PATHVARIABLE, QUERYPARAM, HEADER, BODY, RESPONSE_HEADER, RESPONSE_BODY|VALIDATION
@@ -23,3 +23,4 @@ disableOptionalParameters|boolean|-|false|Whether to set optional parameters as
2323
keepImplicitHeaders|boolean|-|false|Whether to keep implicit headers from the OpenAPI specification, which are removed by default.|CONVERSION
2424
includeWebhooks|boolean|-|false|Select whether to include Webhooks in the generated collection|CONVERSION
2525
includeReferenceMap|boolean|-|false|Whether or not to include reference map or not as part of output|BUNDLE
26+
includeDeprecated|boolean|-|true|Select whether to include deprecated operations, parameters, and properties in generated collection or not|CONVERSION, VALIDATION

README.md

Lines changed: 99 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11

2-
![postman icon](https://raw.githubusercontent.com/postmanlabs/postmanlabs.github.io/develop/global-artefacts/postman-logo%2Btext-320x132.png)
2+
<img src="https://voyager.postman.com/logo/postman-logo-orange.svg" width="320" alt="The Postman Logo">
33

4-
*Supercharge your API workflow.*
4+
*Supercharge your API workflow.*
55
*Modern software is built on APIs. Postman helps you develop APIs faster.*
66

7-
# OpenAPI 3.0 to Postman Collection v2.1.0 Converter
7+
# OpenAPI 3.0, 3.1 and Swagger 2.0 to Postman Collection
88

9-
[![Build Status](https://travis-ci.org/postmanlabs/openapi-to-postman.svg?branch=master)](https://travis-ci.org/postmanlabs/openapi-to-postman)
10-
<a href="https://www.npmjs.com/package/openapi-to-postmanv2" alt="Latest Stable Version">![npm](https://img.shields.io/npm/v/openapi-to-postmanv2.svg)</a>
9+
![Build Status](https://github.com/postmanlabs/openapi-to-postman/actions/workflows/integration.yml/badge.svg)
10+
11+
<a href="https://www.npmjs.com/package/openapi-to-postmanv2" alt="Latest Stable Version">![npm](https://img.shields.io/npm/v/openapi-to-postmanv2.svg)</a>
1112
<a href="https://www.npmjs.com/package/openapi-to-postmanv2" alt="Total Downloads">![npm](https://img.shields.io/npm/dw/openapi-to-postmanv2.svg)</a>
1213

13-
#### Contents
14+
#### Contents
1415

1516
1. [Getting Started](#getting-started)
16-
2. [Using the converter as a NodeJS module](#using-the-converter-as-a-nodejs-module)
17+
2. [Command Line Interface](#command-line-interface)
18+
1. [Options](#options)
19+
2. [Usage](#usage)
20+
3. [Using the converter as a NodeJS module](#using-the-converter-as-a-nodejs-module)
1721
1. [Convert Function](#convert)
1822
2. [Options](#options)
1923
3. [ConversionResult](#conversionresult)
2024
4. [Sample usage](#sample-usage)
2125
5. [Validate function](#validate-function)
22-
3. [Command Line Interface](#command-line-interface)
23-
1. [Options](#options)
24-
2. [Usage](#usage)
2526
4. [Conversion Schema](#conversion-schema)
2627

2728
---
2829

29-
## Getting Started
30+
---
31+
32+
### 🚀 We now also support OpenAPI 3.1 and Swagger 2.0 along with OpenAPI 3.0.
33+
---
34+
---
35+
36+
## 💭 Getting Started
3037

3138
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.
3239

@@ -40,7 +47,64 @@ If you want to use the converter in the CLI, install it globally with NPM:
4047
$ npm i -g openapi-to-postmanv2
4148
```
4249

43-
## Using the converter as a NodeJS module
50+
51+
## 📖 Command Line Interface
52+
53+
The converter can be used as a CLI tool as well. The following [command line options](#options) are available.
54+
55+
`openapi2postmanv2 [options]`
56+
57+
### Options
58+
59+
- `-s <source>`, `--spec <source>`
60+
Used to specify the OpenAPI specification (file path) which is to be converted
61+
62+
- `-o <destination>`, `--output <destination>`
63+
Used to specify the destination file in which the collection is to be written
64+
65+
- `-p`, `--pretty`
66+
Used to pretty print the collection object while writing to a file
67+
68+
- `-O`, `--options`
69+
Used to supply options to the converter, for complete options details see [here](/OPTIONS.md)
70+
71+
- `-c`, `--options-config`
72+
Used to supply options to the converter through config file, for complete options details see [here](/OPTIONS.md)
73+
74+
- `-t`, `--test`
75+
Used to test the collection with an in-built sample specification
76+
77+
- `-v`, `--version`
78+
Specifies the version of the converter
79+
80+
- `-h`, `--help`
81+
Specifies all the options along with a few usage examples on the terminal
82+
83+
84+
### Usage
85+
86+
- Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options
87+
```terminal
88+
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,includeAuthInfoInExample=false
89+
```
90+
91+
- 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
92+
```terminal
93+
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -c ./examples/cli-options-config.json
94+
```
95+
96+
- 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)
97+
```terminal
98+
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,requestParametersResolution=Example,optimizeConversion=false,stackLimit=50
99+
```
100+
101+
- Testing the converter
102+
```terminal
103+
$ openapi2postmanv2 --test
104+
```
105+
106+
107+
## 🛠 Using the converter as a NodeJS module
44108

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

@@ -52,7 +116,7 @@ The converter provides the following functions:
52116

53117
### Convert
54118

55-
The convert function takes in your OpenAPI specification ( YAML / JSON ) and converts it to a Postman collection.
119+
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.
56120

57121
Signature: `convert (data, options, callback);`
58122

@@ -77,6 +141,7 @@ OR
77141
All three properties are optional. Check the options section below for possible values for each option.
78142
*/
79143
```
144+
Note: All possible values of options and their usage can be found over here: [OPTIONS.md](/OPTIONS.md)
80145

81146
**callback:**
82147
```javascript
@@ -95,26 +160,25 @@ function (err, result) {
95160
}
96161
```
97162

98-
### Options:
163+
### Options
99164

100165
Check out complete list of options and their usage at [OPTIONS.md](/OPTIONS.md)
101166

102167
### ConversionResult
103168

104-
- `result` - Flag responsible for providing a status whether the conversion was successful or not
169+
- `result` - Flag responsible for providing a status whether the conversion was successful or not.
105170

106-
- `reason` - Provides the reason for an unsuccessful conversion, defined only if result: false
171+
- `reason` - Provides the reason for an unsuccessful conversion, defined only if result if `false`.
107172

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

110175

111176

112-
### Sample Usage:
177+
### Sample Usage
113178
```javascript
114-
var fs = require('fs'),
115-
116-
Converter = require('openapi-to-postmanv2'),
117-
openapiData = fs.readFileSync('sample-spec.yaml', {encoding: 'UTF8'});
179+
const fs = require('fs'),
180+
Converter = require('openapi-to-postmanv2'),
181+
openapiData = fs.readFileSync('sample-spec.yaml', {encoding: 'UTF8'});
118182

119183
Converter.convert({ type: 'string', data: openapiData },
120184
{}, (err, conversionResult) => {
@@ -152,77 +216,19 @@ The validate function is synchronous and returns a status object which conforms
152216

153217
- `reason` - Provides a reason for an unsuccessful validation of the specification
154218

219+
## 🧭 Conversion Schema
155220

156-
## Command Line Interface
157-
158-
The converter can be used as a CLI tool as well. The following [command line options](#options) are available.
159-
160-
`openapi2postmanv2 [options]`
161-
162-
### Options
163-
- `-v`, `--version`
164-
Specifies the version of the converter
165-
166-
- `-s <source>`, `--spec <source>`
167-
Used to specify the OpenAPI specification (file path) which is to be converted
168-
169-
- `-o <destination>`, `--output <destination>`
170-
Used to specify the destination file in which the collection is to be written
171-
172-
- `-t`, `--test`
173-
Used to test the collection with an in-built sample specification
174-
175-
- `-p`, `--pretty`
176-
Used to pretty print the collection object while writing to a file
177-
178-
- `-O`, `--options`
179-
Used to supply options to the converter, for complete options details see [here](/OPTIONS.md)
180-
181-
- `-c`, `--options-config`
182-
Used to supply options to the converter through config file, for complete options details see [here](/OPTIONS.md)
183-
184-
- `-h`, `--help`
185-
Specifies all the options along with a few usage examples on the terminal
186-
187-
188-
### Usage
189-
190-
**Sample usage examples of the converter CLI**
191-
192-
193-
- Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options
194-
```terminal
195-
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,includeAuthInfoInExample=false
196-
```
197-
198-
- 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
199-
```terminal
200-
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -c ./examples/cli-options-config.json
201-
```
202-
203-
- 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)
204-
```terminal
205-
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,requestParametersResolution=Example,optimizeConversion=false,stackLimit=50
206-
```
207-
208-
- Testing the converter
209-
```terminal
210-
$ openapi2postmanv2 --test
211-
```
212-
213-
## Conversion Schema
214-
215-
| *postman* | *openapi* | *options* | *examples* |
216-
| --- | --- | :---: | :--- |
217-
| collectionName | info.title | - | |
218-
| description | info.description + info.contact | - | |
219-
| collectionVariables| server.variables + pathVariables | - | |
220-
| folderName | paths.path | - | |
221-
| requestName | operationItem(method).operationId | default(operationId)-(`requestName`)enum['operationId','summary','url'] | |
222-
| request.method | path.method | - | |
221+
| *postman* | *openapi* | *related options* |
222+
| --- | --- | :---: |
223+
| collectionName | info.title | - |
224+
| description | info.description + info.contact | - |
225+
| collectionVariables| server.variables + pathVariables | - |
226+
| folderName | paths.path / tags.name | folderStrategy |
227+
| requestName | operationItem(method).summary / operationItem(method).operationId / url | requestNameSource |
228+
| request.method | path.method | - |
223229
| request.headers | parameter (`in = header`) | - | [link](#Header/Path-param-conversion-example) |
224-
| request.body | operationItem(method).requestBody | - | |
225-
| request.url.raw | server.url (path level server >> openapi server) + path | - | |
226-
| request.url.variables | parameter (`in = path`) | - | [link](#Header/Path-param-conversion-example) |
227-
| request.url.params | parameter (`in = query`) | - | {"key": param.name, "value": [link](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-examples)}|
228-
| api_key in (query or header) | components.securitySchemes.api_key | - ||
230+
| request.body | operationItem(method).requestBody | requestParametersResolution, exampleParametersResolution |
231+
| request.url.raw | server.url (path level server >> openapi server) + path | - |
232+
| request.url.variables | parameter (`in = path`) | - |
233+
| request.url.params | parameter (`in = query`) | - |
234+
| api_key in (query or header) | components.securitySchemes.api_key | includeAuthInfoInExample |

lib/deref.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ module.exports = {
149149
*/
150150

151151
resolveRefs: function (schema, parameterSourceOption, components, schemaResolutionCache,
152-
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 10, isAllOf = false) {
152+
resolveFor = 'CONVERSION', resolveTo = 'schema', stack = 0, seenRef = {}, stackLimit = 8, isAllOf = false) {
153153
var resolvedSchema, prop, splitRef,
154154
ERR_TOO_MANY_LEVELS = '<Error: Too many levels of nesting to fake this schema>';
155155
let concreteUtils = components && components.hasOwnProperty('concreteUtils') ?
@@ -247,16 +247,20 @@ module.exports = {
247247
}
248248
return { value: 'reference ' + schema.$ref + ' not found in the OpenAPI spec' };
249249
}
250-
if (concreteUtils.compareTypes(schema.type, SCHEMA_TYPES.object) || schema.hasOwnProperty('properties') ||
251-
schema.hasOwnProperty('additionalProperties')) {
250+
251+
if (
252+
concreteUtils.compareTypes(schema.type, SCHEMA_TYPES.object) ||
253+
schema.hasOwnProperty('properties') ||
254+
(schema.hasOwnProperty('additionalProperties') && !schema.hasOwnProperty('type'))
255+
) {
252256
// go through all props
253257
schema.type = SCHEMA_TYPES.object;
258+
254259
if (_.has(schema, 'properties') || _.has(schema, 'additionalProperties')) {
255-
// shallow cloning schema object except properties object
256260
let tempSchema = _.omit(schema, ['properties', 'additionalProperties']);
261+
// shallow cloning schema object except properties object
257262

258263
if (_.has(schema, 'additionalProperties')) {
259-
// don't resolve boolean values
260264
if (_.isBoolean(schema.additionalProperties)) {
261265
tempSchema.additionalProperties = schema.additionalProperties;
262266
}
@@ -332,7 +336,8 @@ module.exports = {
332336
// have to create a shallow clone of schema object,
333337
// so that the original schema.items object will not change
334338
// without this, schemas with circular references aren't faked correctly
335-
let tempSchema = _.omit(schema, 'items');
339+
let tempSchema = _.omit(schema, ['items', 'additionalProperties']);
340+
336341
tempSchema.items = this.resolveRefs(schema.items, parameterSourceOption,
337342
components, schemaResolutionCache, resolveFor, resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
338343
return tempSchema;

lib/options.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module.exports = {
155155
name: 'Schema resolution nesting limit',
156156
id: 'stackLimit',
157157
type: 'integer',
158-
default: 10,
158+
default: 8,
159159
description: 'Number of nesting limit till which schema resolution will happen. Increasing this limit may' +
160160
' result in more time to convert collection depending on complexity of specification. (To make sure this' +
161161
' option works correctly "optimizeConversion" option needs to be disabled)',
@@ -308,6 +308,17 @@ module.exports = {
308308
external: false,
309309
usage: ['BUNDLE'],
310310
supportedIn: [VERSION20, VERSION30, VERSION31]
311+
},
312+
{
313+
name: 'Include deprecated properties',
314+
id: 'includeDeprecated',
315+
type: 'boolean',
316+
default: true,
317+
description: 'Select whether to include deprecated operations, parameters,' +
318+
' and properties in generated collection or not',
319+
external: true,
320+
usage: ['CONVERSION', 'VALIDATION'],
321+
supportedIn: [VERSION20, VERSION30, VERSION31]
311322
}
312323
];
313324

0 commit comments

Comments
 (0)