1
+ <img src =" https://voyager.postman.com/logo/postman-logo-orange.svg " width =" 320 " alt =" The Postman Logo " >
1
2
2
- <img src =" https://voyager.postman.com/logo/postman-logo-orange.svg " width =" 320 " alt =" The Postman Logo v2 " >
3
-
4
- * Supercharge your API workflow.*
5
- * Modern software is built on APIs. Postman helps you develop APIs faster.*
3
+ _ Supercharge your API workflow._
4
+ _ Modern software is built on APIs. Postman helps you develop APIs faster._
6
5
7
6
# OpenAPI 3.0, 3.1 and Swagger 2.0 to Postman Collection
8
7
15
14
16
15
1 . [ Getting Started] ( #getting-started )
17
16
2 . [ Command Line Interface] ( #command-line-interface )
18
- 1 . [ Options] ( #options )
19
- 2 . [ Usage] ( #usage )
17
+ 1 . [ Options] ( #options )
18
+ 2 . [ Usage] ( #usage )
20
19
3 . [ Using the converter as a NodeJS module] ( #using-the-converter-as-a-nodejs-module )
21
- 1 . [ Convert Function] ( #convert )
22
- 2 . [ Options] ( #options )
23
- 3 . [ ConversionResult] ( #conversionresult )
24
- 4 . [ Sample usage] ( #sample-usage )
25
- 5 . [ Validate function] ( #validate-function )
20
+ 1 . [ Convert Function] ( #convert )
21
+ 2 . [ Options] ( #options )
22
+ 3 . [ ConversionResult] ( #conversionresult )
23
+ 4 . [ Sample usage] ( #sample-usage )
24
+ 5 . [ Validate function] ( #validate-function )
26
25
4 . [ Conversion Schema] ( #conversion-schema )
27
26
28
27
---
29
28
30
29
---
31
30
32
31
### 🚀 We now also support OpenAPI 3.1 and Swagger 2.0 along with OpenAPI 3.0.
32
+
33
33
---
34
+
34
35
---
35
36
36
37
<h2 id =" getting-started " >💭 Getting Started</h2 >
@@ -47,7 +48,6 @@ If you want to use the converter in the CLI, install it globally with NPM:
47
48
$ npm i -g openapi-to-postmanv2
48
49
```
49
50
50
-
51
51
<h2 id =" command-line-interface " >📖 Command Line Interface</h2 >
52
52
53
53
The converter can be used as a CLI tool as well. The following [ command line options] ( #options ) are available.
@@ -83,36 +83,38 @@ The converter can be used as a CLI tool as well. The following [command line opt
83
83
- ` -h ` , ` --help `
84
84
Specifies all the options along with a few usage examples on the terminal
85
85
86
-
87
- ### Usage
86
+ ### Usage
88
87
89
88
- Takes a specification (spec.yaml) as an input and writes to a file (collection.json) with pretty printing and using provided options
89
+
90
90
``` terminal
91
91
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,includeAuthInfoInExample=false
92
92
```
93
93
94
94
- 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
95
+
95
96
``` terminal
96
97
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -c ./examples/cli-options-config.json
97
98
```
98
99
99
100
- 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)
101
+
100
102
``` terminal
101
103
$ openapi2postmanv2 -s spec.yaml -o collection.json -p -O folderStrategy=Tags,requestParametersResolution=Example,optimizeConversion=false,stackLimit=50
102
104
```
103
105
104
106
- Testing the converter
107
+
105
108
``` terminal
106
109
$ openapi2postmanv2 --test
107
110
```
108
111
109
-
110
112
<h2 id =" using-the-converter-as-a-nodejs-module " >🛠 Using the converter as a NodeJS module</h2 >
111
113
112
114
In order to use the convert in your node application, you need to import the package using ` require ` .
113
115
114
116
``` javascript
115
- var Converter = require (' openapi-to-postmanv2' )
117
+ var Converter = require (" openapi-to-postmanv2" );
116
118
```
117
119
118
120
The converter provides the following functions:
134
136
```
135
137
136
138
** options:**
139
+
137
140
``` javascript
138
141
{
139
142
schemaFaker: true ,
144
147
All three properties are optional. Check the options section below for possible values for each option.
145
148
*/
146
149
```
150
+
147
151
Note: All possible values of options and their usage can be found over here: [ OPTIONS.md] ( /OPTIONS.md )
148
152
149
153
** callback:**
154
+
150
155
``` javascript
151
156
function (err , result ) {
152
157
/*
@@ -175,21 +180,24 @@ Check out complete list of options and their usage at [OPTIONS.md](/OPTIONS.md)
175
180
176
181
- ` output ` - Contains an array of Postman objects, each one with a ` type ` and ` data ` . The only type currently supported is ` collection ` .
177
182
178
-
179
-
180
183
### Sample Usage
181
- ``` javascript
182
- const fs = require (' fs' ),
183
- Converter = require (' openapi-to-postmanv2' ),
184
- openapiData = fs .readFileSync (' sample-spec.yaml' , {encoding: ' UTF8' });
185
184
186
- Converter .convert ({ type: ' string' , data: openapiData },
187
- {}, (err , conversionResult ) => {
185
+ ``` javascript
186
+ const fs = require (" fs" ),
187
+ Converter = require (" openapi-to-postmanv2" ),
188
+ openapiData = fs .readFileSync (" sample-spec.yaml" , { encoding: " UTF8" });
189
+
190
+ Converter .convert (
191
+ { type: " string" , data: openapiData },
192
+ {},
193
+ (err , conversionResult ) => {
188
194
if (! conversionResult .result ) {
189
- console .log (' Could not convert' , conversionResult .reason );
190
- }
191
- else {
192
- console .log (' The collection object is: ' , conversionResult .output [0 ].data );
195
+ console .log (" Could not convert" , conversionResult .reason );
196
+ } else {
197
+ console .log (
198
+ " The collection object is: " ,
199
+ conversionResult .output [0 ].data
200
+ );
193
201
}
194
202
}
195
203
);
@@ -215,23 +223,24 @@ The validate function is synchronous and returns a status object which conforms
215
223
```
216
224
217
225
##### Validation object explanation
226
+
218
227
- ` result ` - true if the data looks like OpenAPI and can be passed to the convert function
219
228
220
229
- ` reason ` - Provides a reason for an unsuccessful validation of the specification
221
230
222
231
<h2 id =" conversion-schema " >🧭 Conversion Schema</h2 >
223
232
224
- | * postman * | * openapi * | * related options * |
225
- | --- | --- | :---: |
226
- | collectionName | info.title | - |
227
- | description | info.description + info.contact | - |
228
- | collectionVariables| server.variables + pathVariables | - |
229
- | folderName | paths.path / tags.name | folderStrategy |
230
- | requestName | operationItem(method).summary / operationItem(method).operationId / url | requestNameSource |
231
- | request.method | path.method | - |
232
- | request.headers | parameter (` in = header ` ) | - | [ link] ( #Header/Path-param-conversion-example ) |
233
- | request.body | operationItem(method).requestBody | requestParametersResolution, exampleParametersResolution |
234
- | request.url.raw | server.url (path level server >> openapi server) + path | - |
235
- | request.url.variables | parameter (` in = path ` ) | - |
236
- | request.url.params | parameter (` in = query ` ) | - |
237
- | api_key in (query or header) | components.securitySchemes.api_key | includeAuthInfoInExample |
233
+ | _ postman _ | _ openapi _ | _ related options _ |
234
+ | ---------------------------- | ----------------------------------------------------------------------- | :------------------------------------------------------: | --------------------------------------------- |
235
+ | collectionName | info.title | - |
236
+ | description | info.description + info.contact | - |
237
+ | collectionVariables | server.variables + pathVariables | - |
238
+ | folderName | paths.path / tags.name | folderStrategy |
239
+ | requestName | operationItem(method).summary / operationItem(method).operationId / url | requestNameSource |
240
+ | request.method | path.method | - |
241
+ | request.headers | parameter (` in = header ` ) | - | [ link] ( #Header/Path-param-conversion-example ) |
242
+ | request.body | operationItem(method).requestBody | requestParametersResolution, exampleParametersResolution |
243
+ | request.url.raw | server.url (path level server >> openapi server) + path | - |
244
+ | request.url.variables | parameter (` in = path ` ) | - |
245
+ | request.url.params | parameter (` in = query ` ) | - |
246
+ | api_key in (query or header) | components.securitySchemes.api_key | includeAuthInfoInExample |
0 commit comments