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

Commit

Permalink
fix: should support root paths #63
Browse files Browse the repository at this point in the history
Close #63
  • Loading branch information
joolfe committed Aug 25, 2020
1 parent b6db3f7 commit aff566b
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function postmanToOpenApi (input, output, { info = {}, defaultTag = 'defau
paths
}

const openApiYml = safeDump(openApi)
const openApiYml = safeDump(openApi, { skipInvalid: true })
if (output != null) {
await writeFile(output, openApiYml, 'utf8')
}
Expand Down Expand Up @@ -239,7 +239,7 @@ function parseOptsAuth (optAuth) {
}

/* From the path array compose the real path for OpenApi specs */
function calculatePath (paths, pathDepth) {
function calculatePath (paths = [], pathDepth) {
paths = paths.slice(pathDepth) // path depth
// replace repeated '{' and '}' chars
return '/' + paths.map(path => path.replace(/([{}])\1+/g, '$1'))
Expand Down
7 changes: 7 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const COLLECTION_MULTIPLE_SERVERS = './test/resources/input/MultipleServers.json
const COLLECTION_LICENSE_CONTACT = './test/resources/input/LicenseContact.json'
const COLLECTION_DEPTH_PATH_PARAMS = './test/resources/input/DepthPathParams.json'
const COLLECTION_PARSE_STATUS_CODE = './test/resources/input/ParseStatusCode.json'
const COLLECTION_NO_PATH = './test/resources/input/NoPath.json'

const EXPECTED_BASIC = readFileSync('./test/resources/output/Basic.yml', 'utf8')
const EXPECTED_INFO_OPTS = readFileSync('./test/resources/output/InfoOpts.yml', 'utf8')
Expand All @@ -42,6 +43,7 @@ const EXPECTED_LICENSE_CONTACT_PARTIAL = readFileSync('./test/resources/output/L
const EXPECTED_LICENSE_CONTACT_PARTIAL_2 = readFileSync('./test/resources/output/LicenseContactPartial2.yml', 'utf8')
const EXPECTED_DEPTH_PATH_PARAMS = readFileSync('./test/resources/output/DepthPathParams.yml', 'utf8')
const EXPECTED_PARSE_STATUS_CODE = readFileSync('./test/resources/output/ParseStatus.yml', 'utf8')
const EXPECTED_NO_PATH = readFileSync('./test/resources/output/NoPath.yml', 'utf8')

describe('Library specs', function () {
afterEach('remove file', function () {
Expand Down Expand Up @@ -223,4 +225,9 @@ describe('Library specs', function () {
const result = await postmanToOpenApi(COLLECTION_PARSE_STATUS_CODE)
equal(result, EXPECTED_PARSE_STATUS_CODE)
})

it.only('should parse operation when no path (only domain)', async function () {
const result = await postmanToOpenApi(COLLECTION_NO_PATH)
equal(result, EXPECTED_NO_PATH)
})
})
77 changes: 77 additions & 0 deletions test/resources/input/NoPath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"info": {
"_postman_id": "074ac938-087e-4762-8a33-feadabfa1145",
"name": "No Path",
"description": "API to manage GET methods",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get list of users",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.io?age=45&name=Jhon&review=true&number=23.56&required=my value",
"protocol": "https",
"host": [
"api",
"io"
],
"query": [
{
"key": "age",
"value": "45",
"description": "Filter by age [required]"
},
{
"key": "name",
"value": "Jhon",
"description": "Filter by name [REQUIRED]"
},
{
"key": "review",
"value": "true",
"description": "Indicate if should be reviewed or not"
},
{
"key": "number",
"value": "23.56",
"description": "This is a number"
},
{
"key": "required",
"value": "my value",
"description": "[required] mandatory paraemeter"
}
]
},
"description": "Obtain a list of users that fullfill the conditions of the filters"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"id": "e5a590b1-117c-4050-9541-926b7188ebe0",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "6fb7b705-a3fc-45e0-8a80-3f2b5ce4bf9f",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {}
}
53 changes: 53 additions & 0 deletions test/resources/output/NoPath.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
openapi: 3.0.0
info:
title: No Path
description: API to manage GET methods
version: 1.0.0
servers:
- url: 'https://api.io'
paths:
/:
get:
tags:
- default
summary: Get list of users
description: Obtain a list of users that fullfill the conditions of the filters
parameters:
- name: age
in: query
schema:
type: integer
required: true
description: Filter by age
example: '45'
- name: name
in: query
schema:
type: string
required: true
description: Filter by name
example: Jhon
- name: review
in: query
schema:
type: boolean
description: Indicate if should be reviewed or not
example: 'true'
- name: number
in: query
schema:
type: number
description: This is a number
example: '23.56'
- name: required
in: query
schema:
type: string
required: true
description: mandatory paraemeter
example: my value
responses:
'200':
description: Successful response
content:
application/json: {}

0 comments on commit aff566b

Please sign in to comment.