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 <petoc@users.noreply.github.com>
Co-authored-by: jackkav <jackkav@gmail.com>
This commit is contained in:
Peter C 2023-07-19 11:17:23 +02:00 committed by GitHub
parent ee3695064c
commit 45ee825087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 4 deletions

View File

@ -33,6 +33,41 @@ describe('postman', () => {
})) as HttpsSchemaGetpostmanComJsonCollectionV210; })) as HttpsSchemaGetpostmanComJsonCollectionV210;
describe('headers', () => { 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', () => { describe('awsv4', () => {
it('should not duplicate headers', () => { it('should not duplicate headers', () => {
const request: Request1 = { const request: Request1 = {

View File

@ -136,9 +136,11 @@ export class ImportPostman {
url: this.importUrl(request.url), url: this.importUrl(request.url),
parameters: parameters, parameters: parameters,
method: request.method || 'GET', method: request.method || 'GET',
headers: headers.map(({ key, value }) => ({ headers: headers.map(({ key, value, disabled, description }) => ({
name: key, name: key,
value, value,
...(typeof disabled !== 'undefined' ? { disabled } : {}),
...(typeof description !== 'undefined' ? { description } : {}),
})), })),
body: this.importBody(request.body, headers.find(({ key }) => key === 'Content-Type')?.value), body: this.importBody(request.body, headers.find(({ key }) => key === 'Content-Type')?.value),
authentication, authentication,

View File

@ -48,17 +48,14 @@ const convertToPostman = (items: Swagger[]) => {
{ {
key: 'SOAPAction', key: 'SOAPAction',
value: api['x-ibm-soap']['soap-action'], value: api['x-ibm-soap']['soap-action'],
disabled: false,
}, },
{ {
key: 'Content-Type', key: 'Content-Type',
value: swagger.consumes[0], value: swagger.consumes[0],
disabled: false,
}, },
{ {
key: 'Accept', key: 'Accept',
value: swagger.produces[0], value: swagger.produces[0],
disabled: false,
}, },
], ],
body: { body: {