From 45ee825087f24d20e37019f3e69896ea12c036d0 Mon Sep 17 00:00:00 2001 From: Peter C <63091190+petoc@users.noreply.github.com> Date: Wed, 19 Jul 2023 11:17:23 +0200 Subject: [PATCH] Import all available header properties from Postman (#6162) * import all available header properties from Postman * ignore undefined optional field * fix lint * fix test --------- Co-authored-by: Peter C Co-authored-by: jackkav --- .../utils/importers/importers/postman.test.ts | 35 +++++++++++++++++++ .../src/utils/importers/importers/postman.ts | 4 ++- .../src/utils/importers/importers/wsdl.ts | 3 -- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/packages/insomnia/src/utils/importers/importers/postman.test.ts b/packages/insomnia/src/utils/importers/importers/postman.test.ts index 13cb2b943..b776a6cab 100644 --- a/packages/insomnia/src/utils/importers/importers/postman.test.ts +++ b/packages/insomnia/src/utils/importers/importers/postman.test.ts @@ -33,6 +33,41 @@ describe('postman', () => { })) as HttpsSchemaGetpostmanComJsonCollectionV210; describe('headers', () => { + describe('properties', () => { + it('should import headers with all properties', () => { + const request: Request1 = { + header: [ + { + key: 'X-Header1', + value: 'value1', + description: 'description1', + }, + { + key: 'X-Header2', + value: 'value2', + disabled: true, + }, + ], + }; + const schema = postmanSchema({ requests: [request] }); + const postman = new ImportPostman(schema); + const { headers } = postman.importRequestItem({ request }, 'n/a'); + + expect(headers).toEqual([ + { + name: 'X-Header1', + value: 'value1', + description: 'description1', + }, + { + name: 'X-Header2', + value: 'value2', + disabled: true, + }, + ]); + }); + }); + describe('awsv4', () => { it('should not duplicate headers', () => { const request: Request1 = { diff --git a/packages/insomnia/src/utils/importers/importers/postman.ts b/packages/insomnia/src/utils/importers/importers/postman.ts index 5154db736..5d43c34b4 100644 --- a/packages/insomnia/src/utils/importers/importers/postman.ts +++ b/packages/insomnia/src/utils/importers/importers/postman.ts @@ -136,9 +136,11 @@ export class ImportPostman { url: this.importUrl(request.url), parameters: parameters, method: request.method || 'GET', - headers: headers.map(({ key, value }) => ({ + headers: headers.map(({ key, value, disabled, description }) => ({ name: key, value, + ...(typeof disabled !== 'undefined' ? { disabled } : {}), + ...(typeof description !== 'undefined' ? { description } : {}), })), body: this.importBody(request.body, headers.find(({ key }) => key === 'Content-Type')?.value), authentication, diff --git a/packages/insomnia/src/utils/importers/importers/wsdl.ts b/packages/insomnia/src/utils/importers/importers/wsdl.ts index c0ff9b26a..6963f1615 100644 --- a/packages/insomnia/src/utils/importers/importers/wsdl.ts +++ b/packages/insomnia/src/utils/importers/importers/wsdl.ts @@ -48,17 +48,14 @@ const convertToPostman = (items: Swagger[]) => { { key: 'SOAPAction', value: api['x-ibm-soap']['soap-action'], - disabled: false, }, { key: 'Content-Type', value: swagger.consumes[0], - disabled: false, }, { key: 'Accept', value: swagger.produces[0], - disabled: false, }, ], body: {