Skip to content

Commit

Permalink
Started Postman Collection v2.1.0 support for URLs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Phil Sturgeon committed Jan 16, 2018
1 parent 6765409 commit a471ed7
Show file tree
Hide file tree
Showing 5 changed files with 798 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/loaders/postman/v2.0/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,26 @@ methods.resolve = (options, uri, { $ref = '' } = {}) => {
}

methods.normalizeRequestItem = (item) => {
if (item.request && typeof item.request === 'string') {
if (!item.request) {
return item
}

// If request is a string then make it into a url string and a GET
if (typeof item.request === 'string') {
const url = item.request

item.request = {
url,
method: 'GET'
}
}

// Downgrade Postman Collection v2.1.0's fancy object to a string
const url = item.request.url
if (url && typeof url === 'object' && url.raw) {
item.request.url = url.raw
}

return item
}

Expand Down
8 changes: 6 additions & 2 deletions src/loaders/postman/v2.0/__tests__/Loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ describe('loaders/postman/v2.0/Loader.js', () => {
const inputs = [
{},
{ request: {} },
{ request: 'https://www.example.com' }
// Postman Collection v2.0.0 is a string
{ request: 'https://www.example.com' },
// Postman Collection v2.1.0 is an object
{ request: { url: { raw: 'https://www.example.com' }, method: 'POST' } }
]
const expected = [
{},
{ request: {} },
{ request: { url: 'https://www.example.com', method: 'GET' } }
{ request: { url: 'https://www.example.com', method: 'GET' } },
{ request: { url: 'https://www.example.com', method: 'POST' } }
]
const actual = inputs.map(input => __internals__.normalizeRequestItem(input))
expect(actual).toEqual(expected)
Expand Down
2 changes: 1 addition & 1 deletion testing/e2e/postman-collection2-internal/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const fixDiff = (actual, index) => {
}

describe('postman collection v2 -> internal', () => {
for (let index = 0; index < 1; index += 1) {
for (let index = 0; index < 2; index += 1) {
it('should match expected output for test case #' + index, (done) => {
const output = fs.readFileSync(
resolve(__dirname, './test-case-' + index + '/output.json'),
Expand Down
103 changes: 103 additions & 0 deletions testing/e2e/postman-collection2-internal/test-case-1/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"info": {
"name": "User Management API",
"description": "Certainly not a snippet from a real thing at work",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Users",
"description": "User Management API",
"item": [
{
"name": "Fetch Users",
"request": {
"method": "GET",
"header": [
{
"value": "Bearer {{access_token}}",
"key": "Authorization"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://example.org/users",
"host": [
"http://example.org"
],
"path": [
"users"
]
}
},
"response": []
},
{
"name": "Create a User",
"request": {
"method": "POST",
"header": [
{
"value": "application/json",
"key": "Content-Type"
},
{
"value": "Bearer {{access_token}}",
"key": "Authorization"
}
],
"body": {
"mode": "raw",
"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}"
},
"url": {
"raw": "http://example.org/users",
"host": [
"http://example.org"
],
"path": [
"users"
]
}
},
"response": []
},
{
"name": "Update a User",
"request": {
"method": "PATCH",
"header": [
{
"value": "application/json",
"key": "Content-Type"
},
{
"value": "Bearer {{access_token}}",
"key": "Authorization"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\" : {\n \"attributes\" : {\n \"foo\" : \"bar\",\n \"password\": null\n }\n }\n}"
},
"url": {
"raw": "http://example.org/users/{{user_id}}",
"host": [
"http://example.org"
],
"path": [
"users",
"{{user_id}}"
]
},
"description": "Update an existing user"
},
"response": []
}
]
}
]
}
Loading

0 comments on commit a471ed7

Please sign in to comment.