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

Commit

Permalink
feat: added "defaultTag" as option
Browse files Browse the repository at this point in the history
Now we can decide what is the default tag string
  • Loading branch information
joolfe committed Jul 25, 2020
1 parent 5bf2dc2 commit a3bed58
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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 = {} }) {
async function postmanToOpenApi (input, output, { save = true, info = {}, defaultTag = 'default' }) {
// TODO validate?
const collectionFile = await readFile(input)
const postmanJson = JSON.parse(collectionFile)
Expand All @@ -15,6 +15,7 @@ async function postmanToOpenApi (input, output, { save = true, info = {} }) {
const compiledPath = '/' + path.join('/')
if (!paths[compiledPath]) paths[compiledPath] = {}
paths[compiledPath][method.toLowerCase()] = {
tags: [defaultTag],
summary,
...(description ? { description } : {}),
requestBody: parseBody(body),
Expand Down
6 changes: 6 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const COLLECTION_NO_VERSION = './test/resources/input/NoVersion.json'
const EXPECTED_BASIC = readFileSync('./test/resources/output/Basic.yml', 'utf8')
const EXPECTED_INFO_OPTS = readFileSync('./test/resources/output/InfoOpts.yml', 'utf8')
const EXPECTED_NO_VERSION = readFileSync('./test/resources/output/NoVersion.yml', 'utf8')
const EXPECTED_CUSTOM_TAG = readFileSync('./test/resources/output/CustomTag.yml', 'utf8')

describe('Library specs', function () {
afterEach('remove file', function () {
Expand Down Expand Up @@ -49,4 +50,9 @@ describe('Library specs', function () {
const result = await postmanToOpenApi(COLLECTION_NO_VERSION, OUTPUT_PATH, {})
equal(EXPECTED_NO_VERSION, result)
})

it('should use "defaultTag" provided by config', async function () {
const result = await postmanToOpenApi(COLLECTION_SIMPLE, OUTPUT_PATH, { defaultTag: 'Custom Tag' })
equal(EXPECTED_CUSTOM_TAG, result)
})
})
4 changes: 4 additions & 0 deletions test/resources/output/Basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ info:
paths:
/users:
post:
tags:
- default
summary: Create a user
description: This is a post request with json body
requestBody:
Expand All @@ -25,6 +27,8 @@ paths:
application/json: {}
/posts:
post:
tags:
- default
summary: Create a post
requestBody:
content:
Expand Down
27 changes: 27 additions & 0 deletions test/resources/output/CustomTag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
openapi: 3.0.0
info:
title: Simple Post
description: Just a simple collection for test
version: 2.3.0
paths:
/users:
post:
tags:
- Custom Tag
summary: Create new User
description: Create a new user into your amazing API
requestBody:
content:
application/json:
schema:
type: object
example:
example: field
other:
data1: 'yes'
data2: 'no'
responses:
'200':
description: Successful response
content:
application/json: {}
2 changes: 2 additions & 0 deletions test/resources/output/InfoOpts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ info:
paths:
/users:
post:
tags:
- default
summary: Create new User
description: Create a new user into your amazing API
requestBody:
Expand Down
2 changes: 2 additions & 0 deletions test/resources/output/NoVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ info:
paths:
/users:
post:
tags:
- default
summary: Create new User
description: Create a new user into your amazing API
requestBody:
Expand Down

0 comments on commit a3bed58

Please sign in to comment.