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

Commit f6c3148

Browse files
committed
refactor: Remove save opts #54
1 parent 0ed6a0a commit f6c3148

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

docs/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ Use the library is as easy as use a single method `async postmanToOpenApi(inputP
4343

4444
| Param | Description |
4545
|--------------|---------------------------------------------------------------------------------------------|
46-
| `options` | Object. Optional configuration, see [options](#options) section for a detailed description. |
4746
| `inputPath` | String. Path of the Postman collection file. |
48-
| `outputPath` | String. Path of the output file where the OpenAPi will be stored. |
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.
4951

5052
An example of usage:
5153

@@ -58,6 +60,8 @@ const outputFile = './api/collection.yml'
5860
// Async/await
5961
try {
6062
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 })
6165
console.log(`OpenAPI specs: ${result}`)
6266
} catch (err) {
6367
console.log(err)

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const { promises: { writeFile, readFile } } = require('fs')
44
const { safeDump } = require('js-yaml')
55

6-
async function postmanToOpenApi (input, output, { save = true, info = {}, defaultTag = 'default', auth, servers } = {}) {
6+
async function postmanToOpenApi (input, output, { info = {}, defaultTag = 'default', auth, servers } = {}) {
77
// TODO validate?
88
const collectionFile = await readFile(input)
99
const postmanJson = JSON.parse(collectionFile)
@@ -51,7 +51,7 @@ async function postmanToOpenApi (input, output, { save = true, info = {}, defaul
5151
}
5252

5353
const openApiYml = safeDump(openApi)
54-
if (save) {
54+
if (output != null) {
5555
await writeFile(output, openApiYml, 'utf8')
5656
}
5757
return openApiYml

test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Library specs', function () {
4848
})
4949

5050
it('should work when no save', async function () {
51-
await postmanToOpenApi(COLLECTION_BASIC, '', { save: false })
51+
await postmanToOpenApi(COLLECTION_BASIC, null)
5252
})
5353

5454
it('should work if info is passed as parameter', async function () {

0 commit comments

Comments
 (0)