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

Commit 3f60d9a

Browse files
committed
docs: library options documented.
1 parent dcb1cf7 commit 3f60d9a

1 file changed

Lines changed: 96 additions & 16 deletions

File tree

docs/index.md

Lines changed: 96 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@
77
[![build](https://github.com/joolfe/postman-to-openapi/workflows/Node.js%20CI/badge.svg)](https://github.com/joolfe/postman-to-openapi/actions)
88
[![codecov](https://codecov.io/gh/joolfe/postman-to-openapi/branch/master/graph/badge.svg)](https://codecov.io/gh/joolfe/postman-to-openapi)
99

10-
## Features
10+
## Features at a glance
1111

1212
- Postman Collection v2.1
1313
- 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`.
14+
- Basic info API from Postman info or customizable.
15+
- Basic method conversion (GET, POST, PUT...).
16+
- Support Postman folders as tags.
1717
- Transform query, headers and path parameters.
18-
- Postman variables in as Path parameters.
18+
- Postman variables as Path parameters.
1919
- Automatic infer types from query and headers parameters.
2020
- 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.
21+
- Global Authorization parse or by configuration (Basic and Bearer).
2422

2523
</div></div>
2624
<div class="tilted-section"><div markdown="1">
2725

2826
# Install
2927

30-
```
28+
```bash
3129
npm i postman-to-openapi --save
3230
```
3331

@@ -40,15 +38,15 @@ To use as a cli coming soon...
4038

4139
Use the library is as easy as use a single method `async postmanToOpenApi(inputPath, outputPath, options)`, the parameters are:
4240

43-
| Param | Description |
44-
|-|-|
45-
| `inputPath` | String. Path of the Postman collection file. |
46-
| `outputPath` | String. Path of the output file where the OpenAPi will be stored. |
47-
| `options` | Object. Optional configuration, see [options](#Options) section for a detailed description.|
41+
| Param | Description |
42+
|--------------|---------------------------------------------------------------------------------------------|
43+
| `options` | Object. Optional configuration, see [options](#options) section for a detailed description. |
44+
| `inputPath` | String. Path of the Postman collection file. |
45+
| `outputPath` | String. Path of the output file where the OpenAPi will be stored. |
4846

4947
An example of usage:
5048

51-
```
49+
```js
5250
const postmanToOpenApi = require('postman-to-openapi')
5351

5452
const postmanCollection = './path/to/postman/collection.json'
@@ -74,14 +72,96 @@ postmanToOpenApi(postmanCollection, outputFile, { save: true })
7472

7573
## Options
7674

75+
The third parameter used in the library method is an `options` object containing the optional parameters for the transformation, the allowed parameters are:
76+
77+
### info (Object)
78+
79+
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:
80+
81+
| Param | Description |
82+
|------------------|------------------------------------------------------------------------------------|
83+
| `title` | String. The title of the API. |
84+
| `version` | String. The version of the OpenAPI document. |
85+
| `description` | String. A short description of the API. |
86+
| `termsOfService` | String. A URL to the Terms of Service for the API. MUST be in the format of a URL. |
87+
88+
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:
89+
90+
```js
91+
{
92+
info: {
93+
title: 'Options title',
94+
version: '6.0.7-beta',
95+
description: 'Description from options',
96+
termsOfService: 'http://tos.myweb.com'
97+
}
98+
}
99+
```
100+
101+
### defaultTag (String)
102+
103+
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).
104+
105+
If you want to customize the default tag use the options `defaultTag` to indicate the desired value.
106+
107+
```js
108+
const result = await postmanToOpenApi(postmanCollection, outputFile, { defaultTag: 'API' })
109+
```
110+
111+
### auth (Object)
112+
113+
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:
114+
115+
```js
116+
{
117+
myCustomAuth: {
118+
type: 'http',
119+
scheme: 'bearer',
120+
bearerFormat: 'A resource owner JWT',
121+
description: 'My awesome authentication using bearer'
122+
},
123+
myCustomAuth2: {
124+
type: 'http',
125+
scheme: 'basic',
126+
description: 'My awesome authentication using user and password'
127+
}
128+
}
129+
```
130+
77131
</div></div>
78132
<div class="tilted-section"><div markdown="1">
79133

80134
# Features
81135

136+
## Basic API info
137+
138+
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".
139+
140+
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`.
141+
142+
You can customize all this information with the [Info option](#info-(object)).
143+
144+
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.
145+
146+
## Folders as tags
147+
148+
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.
149+
150+
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.
151+
152+
## Global authorization
153+
154+
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).
155+
156+
Only types 'Basic Auth' and 'Bearer Token' are supported now and not operation individual definition is supported.
157+
158+
You can customize the global authorization definition using the [Auth option](#auth-(object)).
159+
160+
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.
161+
82162
</div></div>
83163
<div class="tilted-section"><div markdown="1">
84164

85-
# Postman collections
165+
# Postman collection examples
86166

87167
</div></div>

0 commit comments

Comments
 (0)