Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit a471ed7

Browse files
author
Phil Sturgeon
committed
Started Postman Collection v2.1.0 support for URLs
URL object were causing empty URLs, which shoved everything into / instead of gracefully figuring it out. Now if a URL is an object with "raw" it'll use the raw string. Proper Postman Collection v2.1.0 support would be fantastic, but for now this is solving a problem I'm having in production.
1 parent 6765409 commit a471ed7

File tree

5 files changed

+798
-4
lines changed

5 files changed

+798
-4
lines changed

src/loaders/postman/v2.0/Loader.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,26 @@ methods.resolve = (options, uri, { $ref = '' } = {}) => {
9595
}
9696

9797
methods.normalizeRequestItem = (item) => {
98-
if (item.request && typeof item.request === 'string') {
98+
if (!item.request) {
99+
return item
100+
}
101+
102+
// If request is a string then make it into a url string and a GET
103+
if (typeof item.request === 'string') {
99104
const url = item.request
105+
100106
item.request = {
101107
url,
102108
method: 'GET'
103109
}
104110
}
105111

112+
// Downgrade Postman Collection v2.1.0's fancy object to a string
113+
const url = item.request.url
114+
if (url && typeof url === 'object' && url.raw) {
115+
item.request.url = url.raw
116+
}
117+
106118
return item
107119
}
108120

src/loaders/postman/v2.0/__tests__/Loader.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@ describe('loaders/postman/v2.0/Loader.js', () => {
130130
const inputs = [
131131
{},
132132
{ request: {} },
133-
{ request: 'https://www.example.com' }
133+
// Postman Collection v2.0.0 is a string
134+
{ request: 'https://www.example.com' },
135+
// Postman Collection v2.1.0 is an object
136+
{ request: { url: { raw: 'https://www.example.com' }, method: 'POST' } }
134137
]
135138
const expected = [
136139
{},
137140
{ request: {} },
138-
{ request: { url: 'https://www.example.com', method: 'GET' } }
141+
{ request: { url: 'https://www.example.com', method: 'GET' } },
142+
{ request: { url: 'https://www.example.com', method: 'POST' } }
139143
]
140144
const actual = inputs.map(input => __internals__.normalizeRequestItem(input))
141145
expect(actual).toEqual(expected)

testing/e2e/postman-collection2-internal/e2e.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const fixDiff = (actual, index) => {
4545
}
4646

4747
describe('postman collection v2 -> internal', () => {
48-
for (let index = 0; index < 1; index += 1) {
48+
for (let index = 0; index < 2; index += 1) {
4949
it('should match expected output for test case #' + index, (done) => {
5050
const output = fs.readFileSync(
5151
resolve(__dirname, './test-case-' + index + '/output.json'),
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"info": {
3+
"name": "User Management API",
4+
"description": "Certainly not a snippet from a real thing at work",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
6+
},
7+
"item": [
8+
{
9+
"name": "Users",
10+
"description": "User Management API",
11+
"item": [
12+
{
13+
"name": "Fetch Users",
14+
"request": {
15+
"method": "GET",
16+
"header": [
17+
{
18+
"value": "Bearer {{access_token}}",
19+
"key": "Authorization"
20+
}
21+
],
22+
"body": {
23+
"mode": "raw",
24+
"raw": ""
25+
},
26+
"url": {
27+
"raw": "http://example.org/users",
28+
"host": [
29+
"http://example.org"
30+
],
31+
"path": [
32+
"users"
33+
]
34+
}
35+
},
36+
"response": []
37+
},
38+
{
39+
"name": "Create a User",
40+
"request": {
41+
"method": "POST",
42+
"header": [
43+
{
44+
"value": "application/json",
45+
"key": "Content-Type"
46+
},
47+
{
48+
"value": "Bearer {{access_token}}",
49+
"key": "Authorization"
50+
}
51+
],
52+
"body": {
53+
"mode": "raw",
54+
"raw": "{\n \"data\" : {\n \"attributes\" : {\n \"username\" : \"user\",\n \"email\" : \"[email protected]\",\n \"firstName\" : \"Some\",\n \"lastName\" : \"User\",\n \"enabled\" : true,\n \"password\" : \"abc123\"\n }\n }\n}"
55+
},
56+
"url": {
57+
"raw": "http://example.org/users",
58+
"host": [
59+
"http://example.org"
60+
],
61+
"path": [
62+
"users"
63+
]
64+
}
65+
},
66+
"response": []
67+
},
68+
{
69+
"name": "Update a User",
70+
"request": {
71+
"method": "PATCH",
72+
"header": [
73+
{
74+
"value": "application/json",
75+
"key": "Content-Type"
76+
},
77+
{
78+
"value": "Bearer {{access_token}}",
79+
"key": "Authorization"
80+
}
81+
],
82+
"body": {
83+
"mode": "raw",
84+
"raw": "{\n \"data\" : {\n \"attributes\" : {\n \"foo\" : \"bar\",\n \"password\": null\n }\n }\n}"
85+
},
86+
"url": {
87+
"raw": "http://example.org/users/{{user_id}}",
88+
"host": [
89+
"http://example.org"
90+
],
91+
"path": [
92+
"users",
93+
"{{user_id}}"
94+
]
95+
},
96+
"description": "Update an existing user"
97+
},
98+
"response": []
99+
}
100+
]
101+
}
102+
]
103+
}

0 commit comments

Comments
 (0)