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

Commit

Permalink
refactor: Remove save opts #54
Browse files Browse the repository at this point in the history
  • Loading branch information
joolfe committed Aug 2, 2020
1 parent 0ed6a0a commit f6c3148
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ Use the library is as easy as use a single method `async postmanToOpenApi(inputP

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

The method return a promise string that contain the yml OpenAPI specification, only is saved to a file if the `outputPath` parameter is provided.

An example of usage:

Expand All @@ -58,6 +60,8 @@ const outputFile = './api/collection.yml'
// Async/await
try {
const result = await postmanToOpenApi(postmanCollection, outputFile, { save: true })
// Without save the result in a file
const result2 = await postmanToOpenApi(postmanCollection, null, { save: true })
console.log(`OpenAPI specs: ${result}`)
} catch (err) {
console.log(err)
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { promises: { writeFile, readFile } } = require('fs')
const { safeDump } = require('js-yaml')

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

const openApiYml = safeDump(openApi)
if (save) {
if (output != null) {
await writeFile(output, openApiYml, 'utf8')
}
return openApiYml
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Library specs', function () {
})

it('should work when no save', async function () {
await postmanToOpenApi(COLLECTION_BASIC, '', { save: false })
await postmanToOpenApi(COLLECTION_BASIC, null)
})

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

0 comments on commit f6c3148

Please sign in to comment.