Skip to content

Commit 36d170f

Browse files
committed
Set authorization placeholder values as postman env variable format
1 parent de68836 commit 36d170f

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

lib/schemaUtils.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,25 +1090,25 @@ module.exports = {
10901090
else if (_.toLower(securityDef.scheme) === 'bearer') {
10911091
helper = {
10921092
type: 'bearer',
1093-
bearer: [{ key: 'token', value: '<Bearer Token>' }]
1093+
bearer: [{ key: 'token', value: '{{bearer_token}}' }]
10941094
};
10951095
}
10961096
else if (_.toLower(securityDef.scheme) === 'digest') {
10971097
helper = {
10981098
type: 'digest',
10991099
digest: [
1100-
{ key: 'username', value: '<Digest Auth Username>' },
1101-
{ key: 'password', value: '<Digest Auth Password>' },
1102-
{ key: 'realm', value: '<realm>' }
1100+
{ key: 'username', value: '{{digest_auth_username}}' },
1101+
{ key: 'password', value: '{{digest_auth_password}}' },
1102+
{ key: 'realm', value: '{{realm}}' }
11031103
]
11041104
};
11051105
}
11061106
else if (_.toLower(securityDef.scheme) === 'oauth' || _.toLower(securityDef.scheme) === 'oauth1') {
11071107
helper = {
11081108
type: 'oauth1',
11091109
oauth1: [
1110-
{ key: 'consumerSecret', value: '<OAuth 1.0 Consumer Key>' },
1111-
{ key: 'consumerKey', value: '<OAuth 1.0 Consumer Secret>' },
1110+
{ key: 'consumerSecret', value: '{{oauth_10_consumer_key}}' },
1111+
{ key: 'consumerKey', value: '{{oauth_10_consumer_secret}}' },
11121112
{ key: 'addParamsToHeader', value: true }
11131113
]
11141114
};
@@ -1197,9 +1197,9 @@ module.exports = {
11971197
apikey: [
11981198
{
11991199
key: 'key',
1200-
value: _.isString(securityDef.name) ? securityDef.name : '<API Key Name>'
1200+
value: _.isString(securityDef.name) ? securityDef.name : '{{api_key_name}}'
12011201
},
1202-
{ key: 'value', value: '<API Key>' },
1202+
{ key: 'value', value: '{{api_key}}' },
12031203
{
12041204
key: 'in',
12051205
value: _.includes(['query', 'header'], securityDef.in) ? securityDef.in : 'header'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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: https://postman-echo.com/get
9+
security:
10+
- bear: []
11+
paths:
12+
/pets/{petId}:
13+
get:
14+
summary: Info for a specific pet
15+
operationId: showPetById
16+
tags:
17+
- pets
18+
parameters:
19+
- name: petId
20+
in: path
21+
required: true
22+
description: The id of the pet to retrieve
23+
schema:
24+
type: string
25+
responses:
26+
default:
27+
description: unexpected error
28+
content:
29+
application/json:
30+
schema:
31+
$ref: "#/components/schemas/Error"
32+
components:
33+
schemas:
34+
Error:
35+
type: object
36+
required:
37+
- code
38+
- message
39+
properties:
40+
code:
41+
type: integer
42+
format: int32
43+
message:
44+
type: string
45+
securitySchemes:
46+
bear:
47+
type: http
48+
scheme: bearer
49+
bearerFormat: JWT

test/unit/base.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ describe('CONVERT FUNCTION TESTS ', function() {
5858
allHTTPMethodsSpec = path.join(__dirname, VALID_OPENAPI_PATH, '/all-http-methods.yaml'),
5959
invalidNullInfo = path.join(__dirname, INVALID_OPENAPI_PATH, '/invalid-null-info.json'),
6060
invalidNullInfoTitle = path.join(__dirname, INVALID_OPENAPI_PATH, '/invalid-info-null-title.json'),
61-
invalidNullInfoVersion = path.join(__dirname, INVALID_OPENAPI_PATH, '/invalid-info-null-version.json');
61+
invalidNullInfoVersion = path.join(__dirname, INVALID_OPENAPI_PATH, '/invalid-info-null-version.json'),
62+
specWithAuth = path.join(__dirname, VALID_OPENAPI_PATH + '/specWithAuth.yaml');
6263

6364

6465
it('Should add collection level auth with type as `bearer`' +
@@ -1291,6 +1292,24 @@ describe('CONVERT FUNCTION TESTS ', function() {
12911292
done();
12921293
});
12931294
});
1295+
1296+
describe('[Github #643] - Generated value for corresponding' +
1297+
' authorization should be as environment variable format', function(done) {
1298+
it('Should convert a collection and set auth placeholder as variable', function() {
1299+
var openapi = fs.readFileSync(specWithAuth, 'utf8');
1300+
Converter.convert({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {
1301+
expect(err).to.be.null;
1302+
expect(conversionResult.result).to.equal(true);
1303+
expect(conversionResult.output.length).to.equal(1);
1304+
expect(conversionResult.output[0].type).to.equal('collection');
1305+
expect(conversionResult.output[0].data).to.have.property('info');
1306+
expect(conversionResult.output[0].data).to.have.property('item');
1307+
expect(conversionResult.output[0].data.item.length).to.equal(1);
1308+
expect(conversionResult.output[0].data.auth.bearer[0].value).to.equal('{{bearer_token}}');
1309+
done();
1310+
});
1311+
});
1312+
});
12941313
});
12951314

12961315
describe('Converting swagger 2.0 files', function() {

0 commit comments

Comments
 (0)