Skip to content

Commit a9d2b9b

Browse files
author
Dhwaneet Bhatt
authored
Merge pull request #729 from postmanlabs/bug/fix-default-value-for-auth-in-request
Fix default value of auth as null in the collection request
2 parents ad29832 + 06b20e9 commit a9d2b9b

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- Fixed the default value of auth in the generated request when it is not resolved.
8+
59
## [v4.13.0] - 2023-05-24
610

711
### Added

libV2/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const sdk = require('postman-collection'),
5252
pathParams = _.get(requestObject, 'request.params.pathParams', []),
5353
headers = _.get(requestObject, 'request.headers', []),
5454
responses = _.get(requestObject, 'request.responses', []),
55-
auth = _.get(requestObject, 'request.auth', []);
55+
auth = _.get(requestObject, 'request.auth', null);
5656

5757
_.forEach(queryParams, (param) => {
5858
requestItem.request.url.addQueryParams(param);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets:
11+
post:
12+
summary: Create a pet
13+
operationId: createPets
14+
tags:
15+
- pets
16+
security:
17+
- auth: [pets.write]
18+
responses:
19+
'201':
20+
description: Null response
21+
default:
22+
description: unexpected error
23+
content:
24+
application/json:
25+
schema:
26+
$ref: "#/components/schemas/Error"
27+
components:
28+
schemas:
29+
Pet:
30+
required:
31+
- id
32+
- name
33+
properties:
34+
id:
35+
type: integer
36+
format: int64
37+
name:
38+
type: string
39+
tag:
40+
type: string
41+
Pets:
42+
type: array
43+
items:
44+
$ref: "#/components/schemas/Pet"
45+
Error:
46+
required:
47+
- code
48+
- message
49+
properties:
50+
code:
51+
type: integer
52+
format: int32
53+
message:
54+
type: string
55+
56+
securitySchemes:
57+
bearerAuth:
58+
type: http
59+
scheme: bearer
60+

test/unit/convertV2.test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ const expect = require('chai').expect,
8989
acceptHeaderExample =
9090
path.join(__dirname, VALID_OPENAPI_PATH, '/acceptHeaderExample.json'),
9191
recursiveRefComponents =
92-
path.join(__dirname, VALID_OPENAPI_PATH, '/recursiveRefComponents.yaml');
92+
path.join(__dirname, VALID_OPENAPI_PATH, '/recursiveRefComponents.yaml'),
93+
securityAuthUnresolvedInPathItem =
94+
path.join(__dirname, VALID_OPENAPI_PATH, '/securityAuthUnresolvedInPathItem.yaml');
9395

9496

9597
describe('The convert v2 Function', function() {
@@ -2290,4 +2292,22 @@ describe('The convert v2 Function', function() {
22902292
done();
22912293
});
22922294
});
2295+
2296+
it('Should generate auth as null when it cannot be resolved from provided security definitions', function(done) {
2297+
const openapi = fs.readFileSync(securityAuthUnresolvedInPathItem, 'utf8');
2298+
Converter.convertV2({ type: 'string', data: openapi }, {},
2299+
(err, conversionResult) => {
2300+
expect(err).to.be.null;
2301+
expect(conversionResult.result).to.equal(true);
2302+
expect(conversionResult.output.length).to.equal(1);
2303+
expect(conversionResult.output[0].type).to.equal('collection');
2304+
expect(conversionResult.output[0].data).to.have.property('info');
2305+
expect(conversionResult.output[0].data).to.have.property('item');
2306+
expect(conversionResult.output[0].data.item.length).to.equal(1);
2307+
2308+
const item = conversionResult.output[0].data.item[0].item[0];
2309+
expect(item.request.auth).to.be.null;
2310+
done();
2311+
});
2312+
});
22932313
});

0 commit comments

Comments
 (0)