Skip to content

Commit 70d3727

Browse files
committed
Merge branch 'develop' into feature/fix-validate-schema-example
2 parents 8d76e35 + 85c135e commit 70d3727

Some content is hidden

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

46 files changed

+5059
-221
lines changed

CHANGELOG.md

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

3+
#### v4.6.0 (December 30, 2022)
4+
* Fixed issue where bundling of multi-file definition was not working correctly for more than 10 params correctly.
5+
* Fixed issue where request name was not using operation description if available.
6+
7+
#### v4.5.0 (December 23, 2022)
8+
* Fixed issue [#11519](https://github.com/postmanlabs/postman-app-support/issues/11519) Collection generated from imported OpenAPI were missing certain properties.
9+
* 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.
10+
* Fixed issue [#11527](https://github.com/postmanlabs/postman-app-support/issues/11527) where generated collection contained empty body when */* was used as content-type.
11+
* 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).
12+
* Fixed issue [#643](https://github.com/postmanlabs/openapi-to-postman/issues/643) Generated value for corresponding authorization should be an environment value.
13+
* Removed travis workflows as GitHub actions are present now.
14+
* Updated README.md to include Swagger 2.0 and OpenAPI 3.1 support.
15+
* Updated README.md to include new postman logo.
16+
317
#### v4.4.0 (November 29, 2022)
418
* Fixed issue where collection folder name for paths were having extra spaces.
519
* 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
@@ -1,6 +1,6 @@
11
id|type|available options|default|description|usage
22
|---|---|---|---|---|---|
3-
requestNameSource|enum|URL, Fallback|Fallback|Determines how the requests inside the generated collection will be named. If “Fallback” is selected, the request will be named after one of the following schema values: `description`, `operationid`, `url`.|CONVERSION, VALIDATION
3+
requestNameSource|enum|URL, Fallback|Fallback|Determines how the requests inside the generated collection will be named. If “Fallback” is selected, the request will be named after one of the following schema values: `summary`, `operationId`, `description`, `url`.|CONVERSION, VALIDATION
44
indentCharacter|enum|Space, Tab|Space|Option for setting indentation character|CONVERSION
55
collapseFolders|boolean|-|true|Importing will collapse all folders that have only one child element and lack persistent folder-level data.|CONVERSION
66
optimizeConversion|boolean|-|true|Optimizes conversion for large specification, disabling this option might affect the performance of conversion.|CONVERSION
@@ -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: 93 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*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

99
![Build Status](https://github.com/postmanlabs/openapi-to-postman/actions/workflows/integration.yml/badge.svg)
1010

@@ -14,20 +14,26 @@
1414
#### Contents
1515

1616
1. [Getting Started](#getting-started)
17-
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)
1821
1. [Convert Function](#convert)
1922
2. [Options](#options)
2023
3. [ConversionResult](#conversionresult)
2124
4. [Sample usage](#sample-usage)
2225
5. [Validate function](#validate-function)
23-
3. [Command Line Interface](#command-line-interface)
24-
1. [Options](#options)
25-
2. [Usage](#usage)
2626
4. [Conversion Schema](#conversion-schema)
2727

2828
---
2929

30-
## 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
3137

3238
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.
3339

@@ -41,7 +47,64 @@ If you want to use the converter in the CLI, install it globally with NPM:
4147
$ npm i -g openapi-to-postmanv2
4248
```
4349

44-
## 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
45108

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

@@ -53,7 +116,7 @@ The converter provides the following functions:
53116

54117
### Convert
55118

56-
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.
57120

58121
Signature: `convert (data, options, callback);`
59122

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

82146
**callback:**
83147
```javascript
@@ -96,26 +160,25 @@ function (err, result) {
96160
}
97161
```
98162

99-
### Options:
163+
### Options
100164

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

103167
### ConversionResult
104168

105-
- `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.
106170

107-
- `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`.
108172

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

111175

112176

113-
### Sample Usage:
177+
### Sample Usage
114178
```javascript
115-
var fs = require('fs'),
116-
117-
Converter = require('openapi-to-postmanv2'),
118-
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'});
119182

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

154217
- `reason` - Provides a reason for an unsuccessful validation of the specification
155218

219+
## 🧭 Conversion Schema
156220

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function createComponentMainKey(tempRef, mainKeys) {
237237
*/
238238
function getTraceFromParentKeyInComponents(nodeContext, tempRef, mainKeys, version, commonPathFromData) {
239239
const parents = [...nodeContext.parents].reverse(),
240-
isArrayKeyRegexp = new RegExp('^\\d$', 'g'),
240+
isArrayKeyRegexp = new RegExp('^\\d+$', 'g'),
241241
key = nodeContext.key,
242242
keyIsAnArrayItem = key.match(isArrayKeyRegexp),
243243
parentKeys = [...parents.map((parent) => {

lib/deref.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -64,7 +64,7 @@ module.exports = {
6464
availableOptions: ['URL', 'Fallback'],
6565
description: 'Determines how the requests inside the generated collection will be named.' +
6666
' If “Fallback” is selected, the request will be named after one of the following schema' +
67-
' values: `description`, `operationid`, `url`.',
67+
' values: `summary`, `operationId`, `description`, `url`.',
6868
external: true,
6969
usage: ['CONVERSION', 'VALIDATION'],
7070
supportedIn: [VERSION20, VERSION30, VERSION31]
@@ -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)