Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 8088789

Browse files
authored
Merge pull request #57 from joolfe/develop
Docs and Configuration
2 parents 3aa017c + 657f4d9 commit 8088789

24 files changed

Lines changed: 871 additions & 338 deletions

.github/workflows/node.js.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
name: Node.js CI
1+
name: Build
22

33
on:
44
push:
55
branches: [ develop, master ]
6-
pull_request:
7-
branches: [ develop, master ]
86

97
jobs:
108
build:
@@ -21,6 +19,14 @@ jobs:
2119
- run: npm ci
2220
- run: npm run lint
2321
- run: npm test
22+
- name: Upload coverage to Codecov
23+
uses: codecov/codecov-action@v1
24+
with:
25+
token: ${{ secrets.CODECOV_TOKEN }}
26+
file: ./coverage/lcov.info
27+
flags: unittests
28+
name: codecov-upload
29+
fail_ci_if_error: true
2430
publish:
2531
if: ${{ github.ref == 'refs/heads/master' }}
2632
needs: build

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
## [1.2.0](https://github.com/joolfe/postman-to-openapi/compare/1.1.0...1.2.0) (2020-08-03)
2+
3+
4+
### Features
5+
6+
* add codecov to pipeline ([c34d5ce](https://github.com/joolfe/postman-to-openapi/commit/c34d5ce89f02a2251f4b58886e000d1505e0f305))
7+
* Servers cfg [#10](https://github.com/joolfe/postman-to-openapi/issues/10) AUTO ([07e68df](https://github.com/joolfe/postman-to-openapi/commit/07e68df413198705e45d55069a71208f0fe378e9))
8+
* Servers cfg [#10](https://github.com/joolfe/postman-to-openapi/issues/10) CONFIG ([0ed6a0a](https://github.com/joolfe/postman-to-openapi/commit/0ed6a0a5037bc69b137e2e42e7706349f0607319))
9+
10+
11+
### Bug Fixes
12+
13+
* codecov step fixes ([d7ffb4e](https://github.com/joolfe/postman-to-openapi/commit/d7ffb4e919f944e9ae8220ea04e80114704a9700))
14+
* security reps updates ([8c7da53](https://github.com/joolfe/postman-to-openapi/commit/8c7da5350d853df32481c238c64e09baf3d6a67c))
15+
16+
17+
### Documentation
18+
19+
* add codecov and badges ([78d2acc](https://github.com/joolfe/postman-to-openapi/commit/78d2accccef63c296db4a1c27811bdfdb473320a)), closes [#49](https://github.com/joolfe/postman-to-openapi/issues/49)
20+
* add docs badged ([5dc9654](https://github.com/joolfe/postman-to-openapi/commit/5dc9654d919ecc6f00786a1cd0aa7be287a15ca2))
21+
* add nom badge ([1f5f407](https://github.com/joolfe/postman-to-openapi/commit/1f5f407f8eefcc18911522af5ee5e1b11f165426))
22+
* added logo to the project ([60ef3cd](https://github.com/joolfe/postman-to-openapi/commit/60ef3cddd0e966a1f5d543aa92ffc9f9ddc12ab0))
23+
* Features documentations [#52](https://github.com/joolfe/postman-to-openapi/issues/52) ([f91f60b](https://github.com/joolfe/postman-to-openapi/commit/f91f60b1bb5cb732490871e2becc937f84cb22fb))
24+
* first structure ([505a03c](https://github.com/joolfe/postman-to-openapi/commit/505a03c854512cecb1af375d4bd5fea78cc2faa5))
25+
* getting started ([dcb1cf7](https://github.com/joolfe/postman-to-openapi/commit/dcb1cf7885c9c40b4cc6a9da11563a87d24417ec)), closes [#47](https://github.com/joolfe/postman-to-openapi/issues/47)
26+
* library options documented. ([3f60d9a](https://github.com/joolfe/postman-to-openapi/commit/3f60d9afc4b4a87b7b3b90e53689f055ec74bb04))
27+
28+
29+
### Code Refactoring
30+
31+
* Improve test coverage [#56](https://github.com/joolfe/postman-to-openapi/issues/56) ([6769c0d](https://github.com/joolfe/postman-to-openapi/commit/6769c0d0d529b8182e7e4557d6625df6f56dfcd8))
32+
* Remove save opts [#54](https://github.com/joolfe/postman-to-openapi/issues/54) ([f6c3148](https://github.com/joolfe/postman-to-openapi/commit/f6c314895e233c2e2b342f50f5e502054e3c7ea9))
33+
* rename workflow ([3c6460e](https://github.com/joolfe/postman-to-openapi/commit/3c6460e0c5c67cf7a2d07de2689beee758f86c92))
34+
135
# [1.1.0](https://github.com/joolfe/postman-to-openapi/compare/1.0.0...1.1.0) (2020-07-28)
236

337

README.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
![logo](./docs/assets/img/logo.png)
22

3-
# postman-to-openapi
3+
# [postman-to-openapi](https://joolfe.github.io/postman-to-openapi/)
44

55
🛸 Convert postman collection to OpenAPI specification.
66

77
Or in other words, transform [this specification](https://schema.getpostman.com/json/collection/v2.1.0/collection.json) to [this one](https://swagger.io/specification/)
88

99
[![build](https://github.com/joolfe/postman-to-openapi/workflows/Node.js%20CI/badge.svg)](https://github.com/joolfe/postman-to-openapi/actions)
10+
[![codecov](https://codecov.io/gh/joolfe/postman-to-openapi/branch/master/graph/badge.svg)](https://codecov.io/gh/joolfe/postman-to-openapi)
11+
[![npm version](https://img.shields.io/npm/v/postman-to-openapi
12+
)](https://www.npmjs.com/package/postman-to-openapi)
13+
[![dcos](https://img.shields.io/badge/docs-here-yellow)](https://joolfe.github.io/postman-to-openapi/)
1014

11-
## Features
12-
13-
- Postman Collection v2.1
14-
- OpenApi 3.0
15-
16-
- POST request with JSON body.
17-
- Allow extract the api version from a collection general `variable`.
18-
- Customize general API information.
19-
- Transform query and headers parameters.
20-
- Automatic infer types from query and headers parameters.
21-
- Support Json and Text body formats.
22-
- Global Authentication and Authorization parse
23-
- Basic
24-
- Bearer
25-
- Global Authentication and Authorization by configuration
15+
## Documentation
16+
17+
All features, usage instructions and help can be found in the [Documentation page](https://joolfe.github.io/postman-to-openapi/)
2618

2719
## Development
2820

changelog.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
options: {
3+
preset: {
4+
name: 'conventionalcommits',
5+
types: [
6+
{ type: 'feat', section: 'Features' },
7+
{ type: 'fix', section: 'Bug Fixes' },
8+
{ type: 'perf', section: 'Performance Improvements' },
9+
{ type: 'revert', section: 'Reverts' },
10+
{ type: 'docs', section: 'Documentation' },
11+
{ type: 'style', section: 'Styles' },
12+
{ type: 'chore', section: 'Miscellaneous Chores' },
13+
{ type: 'refactor', section: 'Code Refactoring' },
14+
{ type: 'test', section: 'Tests' },
15+
{ type: 'build', section: 'Build System' },
16+
{ type: 'ci', section: 'Continuous Integration' }
17+
]
18+
}
19+
}
20+
}

docs/index.md

Lines changed: 176 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,31 @@
44

55
🛸 Convert postman collection to OpenAPI specification, or in other words, transform [this specification](https://schema.getpostman.com/json/collection/v2.1.0/collection.json) to [this one](https://swagger.io/specification/)
66

7-
[![build](https://img.shields.io/github/workflow/status/joolfe/postman-util-lib/Node%20CI?&label=Build&logo=github&style=flat-square)](https://github.com/joolfe/postman-util-lib/actions)
8-
[![codecov](https://img.shields.io/codecov/c/github/joolfe/postman-util-lib?logo=codecov&style=flat-square)](https://codecov.io/gh/joolfe/postman-util-lib)
7+
[![build](https://github.com/joolfe/postman-to-openapi/workflows/Node.js%20CI/badge.svg)](https://github.com/joolfe/postman-to-openapi/actions)
8+
[![codecov](https://codecov.io/gh/joolfe/postman-to-openapi/branch/master/graph/badge.svg)](https://codecov.io/gh/joolfe/postman-to-openapi)
9+
[![npm version](https://badge.fury.io/js/postman-to-openapi.svg)](https://www.npmjs.com/package/postman-to-openapi)
910

10-
## Features
11+
## Features at a glance
1112

1213
- Postman Collection v2.1
1314
- OpenApi 3.0
14-
- Basic method conversion (GET, POST, PUT...)
15-
- Customize general API information.
16-
- Extract the api version from a collection general `variable`.
15+
- Basic info API from Postman info or customizable.
16+
- Basic method conversion (GET, POST, PUT...).
17+
- Support Postman folders as tags.
1718
- Transform query, headers and path parameters.
18-
- Postman variables in as Path parameters.
19+
- Postman variables as Path parameters.
1920
- Automatic infer types from query and headers parameters.
2021
- Support Json and Text body formats.
21-
- Global Authentication and Authorization parse (Basic and Bearer).
22-
- Global Authentication and Authorization by configuration.
23-
- Support Postman folders as tags.
22+
- Global Authorization parse or by configuration (Basic and Bearer).
23+
24+
See [Features](#features) section for more details about how to use each of this features.
2425

2526
</div></div>
2627
<div class="tilted-section"><div markdown="1">
2728

2829
# Install
2930

30-
```
31+
```bash
3132
npm i postman-to-openapi --save
3233
```
3334

@@ -38,22 +39,183 @@ To use as a cli coming soon...
3839

3940
# Usage
4041

41-
```
42+
Use the library is as easy as use a single method `async postmanToOpenApi(inputPath, outputPath, options)`, the parameters are:
43+
44+
| Param | Description |
45+
|--------------|---------------------------------------------------------------------------------------------|
46+
| `inputPath` | String. Path of the Postman collection file. |
47+
| `outputPath` | String. Path of the output file where the OpenAPi will be stored. This param is optional if not provided (`undefined` or `null`) no file will be saved. |
48+
| `options` | Object. Optional configuration, see [options](#options) section for a detailed description. |
49+
50+
The method return a promise string that contain the yml OpenAPI specification, only is saved to a file if the `outputPath` parameter is provided.
51+
52+
An example of usage:
53+
54+
```js
4255
const postmanToOpenApi = require('postman-to-openapi')
4356

44-
const result = await postmanToOpenApi('./path/to/postman/collection.json', './api/collection.yml', { save: true })
57+
const postmanCollection = './path/to/postman/collection.json'
58+
const outputFile = './api/collection.yml'
59+
60+
// Async/await
61+
try {
62+
const result = await postmanToOpenApi(postmanCollection, outputFile, { save: true })
63+
// Without save the result in a file
64+
const result2 = await postmanToOpenApi(postmanCollection, null, { save: true })
65+
console.log(`OpenAPI specs: ${result}`)
66+
} catch (err) {
67+
console.log(err)
68+
}
69+
70+
// Promise callback style
71+
postmanToOpenApi(postmanCollection, outputFile, { save: true })
72+
.then(result => {
73+
console.log(`OpenAPI specs: ${result}`)
74+
})
75+
.catch(err => {
76+
console.log(err)
77+
})
4578
```
4679

4780
## Options
4881

82+
The third parameter used in the library method is an `options` object containing the optional parameters for the transformation, the allowed parameters are:
83+
84+
### info (Object)
85+
86+
The basic information of the API is obtained from Postman collection as described in section [default info](#basic-api-info), but you can customize this parameters using the `info` options that can contain the next parameters:
87+
88+
| Param | Description |
89+
|------------------|------------------------------------------------------------------------------------|
90+
| `title` | String. The title of the API. |
91+
| `version` | String. The version of the OpenAPI document. |
92+
| `description` | String. A short description of the API. |
93+
| `termsOfService` | String. A URL to the Terms of Service for the API. MUST be in the format of a URL. |
94+
95+
Basically this are the required and relevant parameters defined in OpenAPI spec [info object](https://swagger.io/specification/#info-object), an example of the option will be:
96+
97+
```js
98+
{
99+
info: {
100+
title: 'Options title',
101+
version: '6.0.7-beta',
102+
description: 'Description from options',
103+
termsOfService: 'http://tos.myweb.com'
104+
}
105+
}
106+
```
107+
108+
### defaultTag (String)
109+
110+
By default the [tag value](https://swagger.io/specification/#tag-object) "default" is added to all the operations during transformation, unless this operations are inside a folder as described in section [folder as tags](#folders-as-tags).
111+
112+
If you want to customize the default tag use the options `defaultTag` to indicate the desired value.
113+
114+
```js
115+
const result = await postmanToOpenApi(postmanCollection, outputFile, { defaultTag: 'API' })
116+
```
117+
118+
### auth (Object)
119+
120+
The global authorization info can be parse from the Postman collection as described in [Global authorization](#global-authorization) section, but you can customize this info using the `auth` option, this param is a Object that follow the structure of OpenAPI [Security Scheme](https://swagger.io/specification/#security-scheme-object), in this moment only type `http` is supported and schemes `basic` and `bearer`, as an example of this option:
121+
122+
```js
123+
{
124+
myCustomAuth: {
125+
type: 'http',
126+
scheme: 'bearer',
127+
bearerFormat: 'A resource owner JWT',
128+
description: 'My awesome authentication using bearer'
129+
},
130+
myCustomAuth2: {
131+
type: 'http',
132+
scheme: 'basic',
133+
description: 'My awesome authentication using user and password'
134+
}
135+
}
136+
```
137+
138+
### servers (Array)
139+
140+
The global servers list can be parse from the Postman collection as described in [Global servers configuration](#global-servers-configuration) section, but you can customize this info using the `servers` option, this param is an array of objects that follow the structure of OpenAPI [Server Objects](https://swagger.io/specification/#server-object), only `url` and `description` field are supported in this moment, as an example of how to use this option:
141+
142+
```js
143+
{
144+
servers: [
145+
{
146+
url: 'https://awesome.api.sandbox.io',
147+
description: 'Sandbox environment server'
148+
},
149+
{
150+
url: 'https://awesome.api.io',
151+
description: 'Production environment server'
152+
}
153+
]
154+
}
155+
```
156+
49157
</div></div>
50158
<div class="tilted-section"><div markdown="1">
51159

52160
# Features
53161

162+
## Basic conversion
163+
164+
This library support the transformation from Postman collection to all the basic HTTP method as GET, POST, PUT... and also parse the body request of type raw `Json` or `Text` type. [Query parameters](#parameters-parsing) are also supported.
165+
166+
Have a look to the [PostmantoOpenAPI collection](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/PostmantoOpenAPI.json) file for an example of how to use this feature.
167+
168+
## Basic API info
169+
170+
For fill the OpenAPI [info object](https://swagger.io/specification/#info-object) this library use the information defined in Postman [collection](https://learning.postman.com/docs/sending-requests/intro-to-collections/#creating-collections) level as "name" and "description".
171+
172+
Postman don't have any field at collection level that feat with OpenAPI "version" field (is a required field in OpenAPI specification), so this library look for a variable with name `version` in Postman [collection variables](https://learning.postman.com/docs/sending-requests/variables/#defining-collection-variables) or if variable is not defined then will use the default value `1.0.0`.
173+
174+
You can customize all this information with the [Info option](#info-(object)).
175+
176+
Have a look to the [SimplePost collection](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/SimplePost.json) file for an example of how to use this feature.
177+
178+
## Folders as tags
179+
180+
In postman you can add [folders](https://learning.postman.com/docs/sending-requests/intro-to-collections/) inside your collection to group requests and keep the collection clean, in OpenAPI there are no folders but exist the concept of [tags](https://swagger.io/specification/#tag-object) that has the same approximate meaning, this library automatically detect folders and use the name of the folder as tag name in the transformation. Right now is not possible to have more than one tag value for each operation.
181+
182+
Have a look to the [FolderCollection](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/FolderCollection.json) file for an example of how to use this feature.
183+
184+
## Parameters parsing
185+
186+
This library automatically transform query and headers parameters from Postman operations tp OpenAPI specification, the populated info is the name, description and use the value of the parameter as an example.
187+
188+
The default schema used for parameters is `string` but the library try to infer the type of the parameters based on the value using regular expressions, the detected types are `integer`, `number`, `boolean` and `string`, if you find any problem in the inference process please open an issue.
189+
190+
Path parameters are also automatically detected, this library look for [Postman variables](https://learning.postman.com/docs/sending-requests/variables/) in the url as `{{variable}}` and transform to a single curly brace expression as `{variable}` as supported by OpenAPI, also create the parameter definition using the variable name.
191+
192+
Have a look to the [GetMethods collection](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/GetMethods.json), [Headers collection](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/Headers.json) and [PathParams collection](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/PathParams.json) files for examples of how to use this features.
193+
194+
## Global authorization
195+
196+
The OpenAPI root [security]https://swagger.io/specification/#openapi-object) definition is filled using the authorization method defined at Postman Collection [authorization config](https://learning.postman.com/docs/sending-requests/authorization/#inheriting-auth).
197+
198+
Only types 'Basic Auth' and 'Bearer Token' are supported now and not operation individual definition is supported.
199+
200+
You can customize the global authorization definition using the [Auth option](#auth-(object)).
201+
202+
Have a look to the collections [AuthBasic](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/AuthBasic.json) and [AuthBearer](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/AuthBearer.json) for examples of how to use this feature.
203+
204+
## Global servers configuration
205+
206+
The OpenAPI root [servers](https://swagger.io/specification/#openapi-object) definition is filled parsing the urls used in the Postman collections requests, the library use all the different urls for create an array of server (removing duplicated), but normally this is not to usefully as Postman collection only will have one environment url, for this reason you can customize the global servers definition using the [server option](#servers-(array))
207+
208+
If you don't want to include a `servers` array in your OpenAPI spec file you just need to pass an empty array as server option, as for example:
209+
210+
```js
211+
const result = await postmanToOpenApi(postmanCollection, outputFile, { servers: [] })
212+
```
213+
214+
This will remove the `servers` field from the yml specification result.
215+
54216
</div></div>
55217
<div class="tilted-section"><div markdown="1">
56218

57-
# Postman collections
219+
# Postman collection examples
58220

59221
</div></div>

0 commit comments

Comments
 (0)