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

Commit 1827712

Browse files
author
Phil Sturgeon
committed
Support URL objects with raw and not much else
URL objects with raw but not a lot else 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.
1 parent 6765409 commit 1827712

File tree

5 files changed

+801
-11
lines changed

5 files changed

+801
-11
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,27 @@ methods.normalizeRequestURL = (item) => {
270270
return item
271271
}
272272

273-
if (typeof item.request.url === 'string') {
274-
item.request.urlString = item.request.url
275-
item.request.url = methods.createPostmanURLObjectFromURLString(item.request.urlString)
276-
}
277-
else {
278-
if (item.request.url && !item.request.url.domain && item.request.url.host) {
279-
item.request.url.domain = item.request.url.host
273+
let { url, urlString } = item.request
274+
275+
if (typeof url === 'object') {
276+
// Lets just use this raw string, its gonna have everything
277+
if (url.raw) {
278+
item.request.urlString = url.raw
279+
item.request.url = methods.createPostmanURLObjectFromURLString(url.raw)
280+
return item
281+
}
282+
// cater to some random bug before we do the object normalization
283+
if (!url.domain && url.host) {
284+
item.request.url.domain = url.host
280285
}
281286
item.request.urlString = methods.createPostmanURLStringFromURLObject(item.request.url)
287+
return item
282288
}
283289

290+
// It's not an object, hope its a string or numeric that'll act like a string
291+
item.request.urlString = url
292+
item.request.url = methods.createPostmanURLObjectFromURLString(url)
293+
284294
return item
285295
}
286296

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,14 @@ describe('loaders/postman/v2.0/Loader.js', () => {
436436
const inputs = [
437437
{ request: { url: '123' } },
438438
{ request: { url: 234 } },
439-
{ request: { url: { host: 345 } } }
439+
{ request: { url: { raw: 345 } } },
440+
{ request: { url: { host: 456 } } }
440441
]
441442
const expected = [
442443
{ request: { url: '123123', urlString: '123' } },
443-
{ request: { url: 234, urlString: 234 / 2 } },
444-
{ request: { url: { host: 345, domain: 345 }, urlString: 345 / 2 } }
444+
{ request: { url: 234 * 2, urlString: 234 } },
445+
{ request: { url: 345 * 2, urlString: 345 } },
446+
{ request: { url: { host: 456, domain: 456 }, urlString: 456 / 2 } }
445447
]
446448
const actual = inputs.map(input => __internals__.normalizeRequestURL(input))
447449
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)