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

Commit 0ae13c8

Browse files
authored
Merge pull request #162 from weskoerber/fix/collection-wrapper-attrib
Merge into `develop` branch for review and update docs. Thanks for your contribution @weskoerber
2 parents b09ed9d + ddc8edc commit 0ae13c8

5 files changed

Lines changed: 304 additions & 1 deletion

File tree

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ async function postmanToOpenApi (input, output, {
1616
if (replaceVars) {
1717
collectionFile = replacePostmanVariables(collectionFile, additionalVars)
1818
}
19-
const postmanJson = JSON.parse(collectionFile)
19+
const _postmanJson = JSON.parse(collectionFile)
20+
const postmanJson = _postmanJson.collection || _postmanJson
2021
const { item: items, variable = [] } = postmanJson
2122
const paths = {}
2223
const domains = new Set()

test/index.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const EXPECTED_VARIABLES_ADDITIONAL = readFileSync('./test/resources/output/Vari
5656
const EXPECTED_BASEPATH_VAR = readFileSync('./test/resources/output/BasepathVar.yml', 'utf8')
5757
const EXPECTED_RAW_BODY = readFileSync('./test/resources/output/RawBody.yml', 'utf8')
5858
const EXPECTED_NULL_HEADER = readFileSync('./test/resources/output/NullHeader.yml', 'utf8')
59+
const EXPECTED_COLLECTION_WRAPPER = readFileSync('./test/resources/output/CollectionWrapper.yml', 'utf8')
5960

6061
const AUTH_DEFINITIONS = {
6162
myCustomAuth: {
@@ -115,6 +116,7 @@ describe('Library specs', function () {
115116
const COLLECTION_VARIABLES = `./test/resources/input/${version}/Variables.json`
116117
const COLLECTION_BASEURL_VAR = `./test/resources/input/${version}/BasepathVar.json`
117118
const COLLECTION_RAW_BODY = `./test/resources/input/${version}/RawBody.json`
119+
const COLLECTION_COLLECTION_WRAPPER = `./test/resources/input/${version}/CollectionWrapper.json`
118120

119121
it('should work with a basic transform', async function () {
120122
const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH, {})
@@ -460,6 +462,11 @@ describe('Library specs', function () {
460462
const result = await postmanToOpenApi(COLLECTION_RAW_BODY, OUTPUT_PATH, {})
461463
equal(result, EXPECTED_RAW_BODY)
462464
})
465+
466+
it('should work with collection wrapper attribute', async function () {
467+
const result = await postmanToOpenApi(COLLECTION_COLLECTION_WRAPPER, OUTPUT_PATH, {})
468+
equal(result, EXPECTED_COLLECTION_WRAPPER)
469+
})
463470
})
464471
})
465472

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"collection": {
3+
"info": {
4+
"_postman_id": "0f93eca8-921e-4b0d-9ac0-15f96a56eae8",
5+
"name": "AuthBasic",
6+
"description": "Collection to test authorization global",
7+
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
8+
},
9+
"item": [
10+
{
11+
"name": "Create new User Copy",
12+
"request": {
13+
"method": "POST",
14+
"header": [],
15+
"body": {
16+
"mode": "raw",
17+
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
18+
"options": {
19+
"raw": {
20+
"language": "json"
21+
}
22+
}
23+
},
24+
"url": "https://api.io/users",
25+
"description": "Create a new user into your amazing API"
26+
},
27+
"response": []
28+
},
29+
{
30+
"name": "Get list of users",
31+
"request": {
32+
"method": "GET",
33+
"header": [],
34+
"url": {
35+
"raw": "https://api.io/users?age=45&name=Jhon&review=true&number=23.56",
36+
"protocol": "https",
37+
"host": [
38+
"api",
39+
"io"
40+
],
41+
"path": [
42+
"users"
43+
],
44+
"query": [
45+
{
46+
"key": "age",
47+
"value": "45",
48+
"description": "Filter by age"
49+
},
50+
{
51+
"key": "name",
52+
"value": "Jhon",
53+
"description": "Filter by name"
54+
},
55+
{
56+
"key": "review",
57+
"value": "true",
58+
"description": "Indicate if should be reviewed or not"
59+
},
60+
{
61+
"key": "number",
62+
"value": "23.56",
63+
"description": "This is a number"
64+
}
65+
]
66+
},
67+
"description": "Obtain a list of users that fullfill the conditions of the filters"
68+
},
69+
"response": []
70+
}
71+
],
72+
"auth": {
73+
"type": "basic",
74+
"basic": {
75+
"password": "ssss",
76+
"username": "sss"
77+
}
78+
},
79+
"event": [
80+
{
81+
"listen": "prerequest",
82+
"script": {
83+
"id": "7b3e1a28-e253-4cd9-ac26-2d9d52092d80",
84+
"type": "text/javascript",
85+
"exec": [
86+
""
87+
]
88+
}
89+
},
90+
{
91+
"listen": "test",
92+
"script": {
93+
"id": "b50e4ce3-8104-4eb7-bc20-50e6f3f5edab",
94+
"type": "text/javascript",
95+
"exec": [
96+
""
97+
]
98+
}
99+
}
100+
],
101+
"protocolProfileBehavior": {}
102+
}
103+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"collection": {
3+
"info": {
4+
"_postman_id": "2c1cccde-7a4d-4dea-bcd8-ce39544b0432",
5+
"name": "AuthBasic",
6+
"description": "Collection to test authorization global",
7+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
8+
},
9+
"item": [
10+
{
11+
"name": "Create new User Copy",
12+
"request": {
13+
"method": "POST",
14+
"header": [],
15+
"body": {
16+
"mode": "raw",
17+
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
18+
"options": {
19+
"raw": {
20+
"language": "json"
21+
}
22+
}
23+
},
24+
"url": {
25+
"raw": "https://api.io/users",
26+
"protocol": "https",
27+
"host": [
28+
"api",
29+
"io"
30+
],
31+
"path": [
32+
"users"
33+
]
34+
},
35+
"description": "Create a new user into your amazing API"
36+
},
37+
"response": []
38+
},
39+
{
40+
"name": "Get list of users",
41+
"request": {
42+
"method": "GET",
43+
"header": [],
44+
"url": {
45+
"raw": "https://api.io/users?age=45&name=Jhon&review=true&number=23.56",
46+
"protocol": "https",
47+
"host": [
48+
"api",
49+
"io"
50+
],
51+
"path": [
52+
"users"
53+
],
54+
"query": [
55+
{
56+
"key": "age",
57+
"value": "45",
58+
"description": "Filter by age"
59+
},
60+
{
61+
"key": "name",
62+
"value": "Jhon",
63+
"description": "Filter by name"
64+
},
65+
{
66+
"key": "review",
67+
"value": "true",
68+
"description": "Indicate if should be reviewed or not"
69+
},
70+
{
71+
"key": "number",
72+
"value": "23.56",
73+
"description": "This is a number"
74+
}
75+
]
76+
},
77+
"description": "Obtain a list of users that fullfill the conditions of the filters"
78+
},
79+
"response": []
80+
}
81+
],
82+
"auth": {
83+
"type": "basic",
84+
"basic": [
85+
{
86+
"key": "password",
87+
"value": "ssss",
88+
"type": "string"
89+
},
90+
{
91+
"key": "username",
92+
"value": "sss",
93+
"type": "string"
94+
}
95+
]
96+
},
97+
"event": [
98+
{
99+
"listen": "prerequest",
100+
"script": {
101+
"id": "631b8a30-dcaf-449a-9f2e-83a9f13044ae",
102+
"type": "text/javascript",
103+
"exec": [
104+
""
105+
]
106+
}
107+
},
108+
{
109+
"listen": "test",
110+
"script": {
111+
"id": "b43e5a36-2b9e-47a0-aab9-edc036b968a6",
112+
"type": "text/javascript",
113+
"exec": [
114+
""
115+
]
116+
}
117+
}
118+
],
119+
"protocolProfileBehavior": {}
120+
}
121+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
openapi: 3.0.0
2+
info:
3+
title: AuthBasic
4+
description: Collection to test authorization global
5+
version: 1.0.0
6+
servers:
7+
- url: https://api.io
8+
components:
9+
securitySchemes:
10+
basicAuth:
11+
type: http
12+
scheme: basic
13+
security:
14+
- basicAuth: []
15+
paths:
16+
/users:
17+
post:
18+
tags:
19+
- default
20+
summary: Create new User Copy
21+
description: Create a new user into your amazing API
22+
requestBody:
23+
content:
24+
application/json:
25+
schema:
26+
type: object
27+
example:
28+
example: field
29+
other:
30+
data1: 'yes'
31+
data2: 'no'
32+
responses:
33+
'200':
34+
description: Successful response
35+
content:
36+
application/json: {}
37+
get:
38+
tags:
39+
- default
40+
summary: Get list of users
41+
description: Obtain a list of users that fullfill the conditions of the filters
42+
parameters:
43+
- name: age
44+
in: query
45+
schema:
46+
type: integer
47+
description: Filter by age
48+
example: '45'
49+
- name: name
50+
in: query
51+
schema:
52+
type: string
53+
description: Filter by name
54+
example: Jhon
55+
- name: review
56+
in: query
57+
schema:
58+
type: boolean
59+
description: Indicate if should be reviewed or not
60+
example: 'true'
61+
- name: number
62+
in: query
63+
schema:
64+
type: number
65+
description: This is a number
66+
example: '23.56'
67+
responses:
68+
'200':
69+
description: Successful response
70+
content:
71+
application/json: {}

0 commit comments

Comments
 (0)