Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5207 - Query parameters ignored when importing Postman collection #5271

Merged
merged 4 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"url": "https://insomnia.rest?foo=bar",
"url": "https://insomnia.rest",
"name": "Test Request",
"description": "",
"parameters": [],
"parameters": [
{
"name": "foo",
"value": "bar",
"disabled": false
}
],
"method": "GET",
"body": {},
"headers": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"url": "https://insomnia.rest?foo=bar",
"url": "https://insomnia.rest",
"name": "Test Request",
"parameters": [],
"parameters": [
{
"name": "foo",
"value": "bar",
"disabled": false
}
],
"description": "",
"method": "GET",
"body": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@
],
"method": "GET",
"name": "Return the complete project hierarchy.",
"parameters": [],
"parameters": [
{
"name": "team_id",
"value": "",
"disabled": true
}
],
"parentId": "__GRP_2__",
"url": ""
},
Expand Down Expand Up @@ -78,7 +84,23 @@
],
"method": "GET",
"name": "Return a list containing all projects.",
"parameters": [],
"parameters": [
{
"name": "title",
"value": "root",
"disabled": false
},
{
"name": "hide_archived",
"value": "true",
"disabled": false
},
{
"name": "team_id",
"value": "",
"disabled": true
}
],
"parentId": "__GRP_2__",
"url": ""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@
"request",
"any"
],
"query": [
{
"key": "foo",
"value": "bar",
"disabled": true
}
]
"query": []
}
},
"response": []
Expand Down Expand Up @@ -200,13 +194,7 @@
"request",
"any"
],
"query": [
{
"key": "foo",
"value": "bar",
"disabled": true
}
]
"query": []
}
},
"response": []
Expand Down Expand Up @@ -298,13 +286,7 @@
"request",
"any"
],
"query": [
{
"key": "foo",
"value": "bar",
"disabled": true
}
]
"query": []
}
},
"response": []
Expand Down Expand Up @@ -406,13 +388,7 @@
"request",
"any"
],
"query": [
{
"key": "foo",
"value": "bar",
"disabled": true
}
]
"query": []
}
},
"response": []
Expand Down Expand Up @@ -511,13 +487,7 @@
"request",
"any"
],
"query": [
{
"key": "foo",
"value": "bar",
"disabled": true
}
]
"query": []
}
},
"response": []
Expand Down
23 changes: 23 additions & 0 deletions packages/insomnia-importers/src/importers/postman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
Header as V210Header,
HttpsSchemaGetpostmanComJsonCollectionV210 as V210Schema,
Item as V210Item,
QueryParam,
Request1 as V210Request1,
UrlEncodedParameter as V210UrlEncodedParameter,
Variable2 as V210Variable2,
Expand Down Expand Up @@ -123,13 +124,19 @@ export class ImportPostman {

const { authentication, headers } = this.importAuthentication(request.auth, request.header as Header[]);

let parameters = [] as Parameter[];

if (typeof request.url === 'object' && request.url.query) {
parameters = this.importParameters(request.url?.query);
}
return {
parentId,
_id: `__REQ_${requestCount++}__`,
_type: 'request',
name,
description: (request.description as string) || '',
url: this.importUrl(request.url),
parameters: parameters,
method: request.method || 'GET',
headers: headers.map(({ key, value }) => ({
name: key,
Expand All @@ -140,6 +147,17 @@ export class ImportPostman {
};
};

importParameters = (parameters: QueryParam[]): Parameter[] => {
if (!parameters || parameters?.length === 0) {
return [];
}
return parameters.map(({ key, value, disabled }) => ({
name: key,
value,
disabled: disabled || false,
}) as Parameter);
};

importFolderItem = ({ name, description }: Folder, parentId: string) => {
return {
parentId,
Expand Down Expand Up @@ -178,6 +196,11 @@ export class ImportPostman {
return '';
}

// remove ? and everything after it if there are QueryParams strictly defined
if (typeof url === 'object' && url.query && url.raw?.includes('?')) {
return url.raw?.slice(0, url.raw.indexOf('?')) || '';
}

if (typeof url === 'object' && url.raw) {
return url.raw;
}
Expand Down