Skip to content

Commit

Permalink
Merge pull request #145 from joolfe/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
joolfe authored Aug 14, 2021
2 parents 2cacd9a + 9791f36 commit cfa3f15
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 164 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
### [1.17.1](https://github.com/joolfe/postman-to-openapi/compare/1.17.0...1.17.1) (2021-08-14)


### Bug Fixes

* scrape Url error close [#136](https://github.com/joolfe/postman-to-openapi/issues/136) ([dda9168](https://github.com/joolfe/postman-to-openapi/commit/dda9168896b7d06b79a721f5e14dbdb56c6d8665))


### Build System

* update version ([82939b9](https://github.com/joolfe/postman-to-openapi/commit/82939b9a157bd6665017d60e85af9eac6b48aaa6))

## [1.17.0](https://github.com/joolfe/postman-to-openapi/compare/1.16.1...1.17.0) (2021-08-07)


Expand Down
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ function scrapeURL (url) {
return { valid: false }
}
const rawUrl = (typeof url === 'string' || url instanceof String) ? url : url.raw
const objUrl = new URL(rawUrl)
// Fix for issue #136 if replace vars are not used then new URL throw an error
// when using variables before the schema
const fixedUrl = (rawUrl.startsWith('{{')) ? 'http://' + rawUrl : rawUrl
const objUrl = new URL(fixedUrl)
return {
raw: rawUrl,
path: decodeURIComponent(objUrl.pathname).slice(1).split('/'),
Expand Down
362 changes: 200 additions & 162 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postman-to-openapi",
"version": "1.17.0",
"version": "1.17.1",
"description": "Convert postman collection to OpenAPI spec",
"main": "lib/index.js",
"types": "types/index.d.ts",
Expand Down
18 changes: 18 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const EXPECTED_FORM_DATA = readFileSync('./test/resources/output/FormData.yml',
const EXPECTED_FORM_URLENCODED = readFileSync('./test/resources/output/FormUrlencoded.yml', 'utf8')
const EXPECTED_VARIABLES = readFileSync('./test/resources/output/Variables.yml', 'utf8')
const EXPECTED_VARIABLES_ADDITIONAL = readFileSync('./test/resources/output/VariablesAdditional.yml', 'utf8')
const EXPECTED_BASEPATH_VAR = readFileSync('./test/resources/output/BasepathVar.yml', 'utf8')

const AUTH_DEFINITIONS = {
myCustomAuth: {
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('Library specs', function () {
const COLLECTION_FORM_DATA = `./test/resources/input/${version}/FormData.json`
const COLLECTION_FORM_URLENCODED = `./test/resources/input/${version}/FormUrlencoded.json`
const COLLECTION_VARIABLES = `./test/resources/input/${version}/Variables.json`
const COLLECTION_BASEURL_VAR = `./test/resources/input/${version}/BasepathVar.json`

it('should work with a basic transform', async function () {
const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH, {})
Expand Down Expand Up @@ -433,6 +435,22 @@ describe('Library specs', function () {
const result = await postmanToOpenApi(COLLECTION_FORM_DATA, OUTPUT_PATH, { replaceVars: true })
equal(result, EXPECTED_FORM_DATA)
})

it('should not fail if url has a base path but is not replaced', async function () {
const result = await postmanToOpenApi(COLLECTION_BASEURL_VAR, OUTPUT_PATH, {
servers: [
{
url: 'https://awesome.api.sandbox.io',
description: 'Sandbox environment server'
},
{
url: 'https://awesome.api.io',
description: 'Production env'
}
]
})
equal(result, EXPECTED_BASEPATH_VAR)
})
})
})

Expand Down
74 changes: 74 additions & 0 deletions test/resources/input/v2/BasepathVar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"info": {
"_postman_id": "033eef66-b948-4d5f-8c7b-a38fea9932f4",
"name": "Basepath Var",
"description": "Just a simple collection for test",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "Create new User",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "{{base_url}}/users",
"description": "Create a new user into your amazing API"
},
"response": []
},
{
"name": "Post empty raw",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "{{base_url}}/raw",
"description": "Create a new user into your amazing API"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "version",
"value": "2.3.0"
}
]
}
90 changes: 90 additions & 0 deletions test/resources/input/v21/BasepathVar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"info": {
"_postman_id": "033eef66-b948-4d5f-8c7b-a38fea9932f4",
"name": "Basepath Var",
"description": "Just a simple collection for test",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create new User",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/users",
"host": [
"{{base_url}}"
],
"path": [
"users"
]
},
"description": "Create a new user into your amazing API"
},
"response": []
},
{
"name": "Post empty raw",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/raw",
"host": [
"{{base_url}}"
],
"path": [
"raw"
]
},
"description": "Create a new user into your amazing API"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "version",
"value": "2.3.0"
}
]
}
49 changes: 49 additions & 0 deletions test/resources/output/BasepathVar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
openapi: 3.0.0
info:
title: Basepath Var
description: Just a simple collection for test
version: 2.3.0
servers:
- url: https://awesome.api.sandbox.io
description: Sandbox environment server
- url: https://awesome.api.io
description: Production env
paths:
/users:
post:
tags:
- default
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: {}
/raw:
post:
tags:
- default
summary: Post empty raw
description: Create a new user into your amazing API
requestBody:
content:
application/json:
schema:
type: object
example: ''
responses:
'200':
description: Successful response
content:
application/json: {}

0 comments on commit cfa3f15

Please sign in to comment.