Skip to content

Commit

Permalink
Fix Kong#5207 - Query parameters ignored when importing Postman colle…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
filfreire committed Oct 13, 2022
1 parent 60bf0f9 commit 8f4a91b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 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,17 @@ export class ImportPostman {

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

// @ts-expect-error - property query does not exist?
const parameters = this.importParameters(request.url.query as QueryParam[]);

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 +145,17 @@ export class ImportPostman {
};
};

importParameters = (parameters: QueryParam[]): Parameter[] => {
if (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 +194,11 @@ export class ImportPostman {
return '';
}

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

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

0 comments on commit 8f4a91b

Please sign in to comment.