Skip to content

Commit

Permalink
Merge pull request #163 from joolfe/develop
Browse files Browse the repository at this point in the history
new feat for support collection downloaded from API
  • Loading branch information
joolfe authored Oct 16, 2021
2 parents f9c6b7f + cc714b5 commit 630f0f2
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 10 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [1.18.0](https://github.com/joolfe/postman-to-openapi/compare/1.17.5...1.18.0) (2021-10-16)


### Bug Fixes

* convert collections with `collection` wrapper attribute ([ddc8edc](https://github.com/joolfe/postman-to-openapi/commit/ddc8edcc752f062117db4a9e59ffded89898f2d8)), closes [#120](https://github.com/joolfe/postman-to-openapi/issues/120) [#161](https://github.com/joolfe/postman-to-openapi/issues/161)


### Build System

* update version and some deps ([b9cde95](https://github.com/joolfe/postman-to-openapi/commit/b9cde95db7ea37e1673e410c43d54997e3fed424))

### [1.17.5](https://github.com/joolfe/postman-to-openapi/compare/1.17.4...1.17.5) (2021-10-03)


Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ async function postmanToOpenApi (input, output, {
if (replaceVars) {
collectionFile = replacePostmanVariables(collectionFile, additionalVars)
}
const postmanJson = JSON.parse(collectionFile)
const _postmanJson = JSON.parse(collectionFile)
const postmanJson = _postmanJson.collection || _postmanJson
const { item: items, variable = [] } = postmanJson
const paths = {}
const domains = new Set()
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.5",
"version": "1.18.0",
"description": "Convert postman collection to OpenAPI spec",
"main": "lib/index.js",
"types": "types/index.d.ts",
Expand Down
7 changes: 7 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const EXPECTED_VARIABLES_ADDITIONAL = readFileSync('./test/resources/output/Vari
const EXPECTED_BASEPATH_VAR = readFileSync('./test/resources/output/BasepathVar.yml', 'utf8')
const EXPECTED_RAW_BODY = readFileSync('./test/resources/output/RawBody.yml', 'utf8')
const EXPECTED_NULL_HEADER = readFileSync('./test/resources/output/NullHeader.yml', 'utf8')
const EXPECTED_COLLECTION_WRAPPER = readFileSync('./test/resources/output/CollectionWrapper.yml', 'utf8')

const AUTH_DEFINITIONS = {
myCustomAuth: {
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('Library specs', function () {
const COLLECTION_VARIABLES = `./test/resources/input/${version}/Variables.json`
const COLLECTION_BASEURL_VAR = `./test/resources/input/${version}/BasepathVar.json`
const COLLECTION_RAW_BODY = `./test/resources/input/${version}/RawBody.json`
const COLLECTION_COLLECTION_WRAPPER = `./test/resources/input/${version}/CollectionWrapper.json`

it('should work with a basic transform', async function () {
const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH, {})
Expand Down Expand Up @@ -460,6 +462,11 @@ describe('Library specs', function () {
const result = await postmanToOpenApi(COLLECTION_RAW_BODY, OUTPUT_PATH, {})
equal(result, EXPECTED_RAW_BODY)
})

it('should work with collection wrapper attribute', async function () {
const result = await postmanToOpenApi(COLLECTION_COLLECTION_WRAPPER, OUTPUT_PATH, {})
equal(result, EXPECTED_COLLECTION_WRAPPER)
})
})
})

Expand Down
103 changes: 103 additions & 0 deletions test/resources/input/v2/CollectionWrapper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"collection": {
"info": {
"_postman_id": "0f93eca8-921e-4b0d-9ac0-15f96a56eae8",
"name": "AuthBasic",
"description": "Collection to test authorization global",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "Create new User Copy",
"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": "https://api.io/users",
"description": "Create a new user into your amazing API"
},
"response": []
},
{
"name": "Get list of users",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.io/users?age=45&name=Jhon&review=true&number=23.56",
"protocol": "https",
"host": [
"api",
"io"
],
"path": [
"users"
],
"query": [
{
"key": "age",
"value": "45",
"description": "Filter by age"
},
{
"key": "name",
"value": "Jhon",
"description": "Filter by name"
},
{
"key": "review",
"value": "true",
"description": "Indicate if should be reviewed or not"
},
{
"key": "number",
"value": "23.56",
"description": "This is a number"
}
]
},
"description": "Obtain a list of users that fullfill the conditions of the filters"
},
"response": []
}
],
"auth": {
"type": "basic",
"basic": {
"password": "ssss",
"username": "sss"
}
},
"event": [
{
"listen": "prerequest",
"script": {
"id": "7b3e1a28-e253-4cd9-ac26-2d9d52092d80",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "b50e4ce3-8104-4eb7-bc20-50e6f3f5edab",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {}
}
}
121 changes: 121 additions & 0 deletions test/resources/input/v21/CollectionWrapper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"collection": {
"info": {
"_postman_id": "2c1cccde-7a4d-4dea-bcd8-ce39544b0432",
"name": "AuthBasic",
"description": "Collection to test authorization global",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create new User Copy",
"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": "https://api.io/users",
"protocol": "https",
"host": [
"api",
"io"
],
"path": [
"users"
]
},
"description": "Create a new user into your amazing API"
},
"response": []
},
{
"name": "Get list of users",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.io/users?age=45&name=Jhon&review=true&number=23.56",
"protocol": "https",
"host": [
"api",
"io"
],
"path": [
"users"
],
"query": [
{
"key": "age",
"value": "45",
"description": "Filter by age"
},
{
"key": "name",
"value": "Jhon",
"description": "Filter by name"
},
{
"key": "review",
"value": "true",
"description": "Indicate if should be reviewed or not"
},
{
"key": "number",
"value": "23.56",
"description": "This is a number"
}
]
},
"description": "Obtain a list of users that fullfill the conditions of the filters"
},
"response": []
}
],
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "ssss",
"type": "string"
},
{
"key": "username",
"value": "sss",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"id": "631b8a30-dcaf-449a-9f2e-83a9f13044ae",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "b43e5a36-2b9e-47a0-aab9-edc036b968a6",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {}
}
}
Loading

0 comments on commit 630f0f2

Please sign in to comment.