Skip to content

Commit

Permalink
fix(definitions): avoid undefined
Browse files Browse the repository at this point in the history
do not process unknown security definition keys unless it is prefixed with x-
  • Loading branch information
syroegkin committed Jun 1, 2019
1 parent d8e6e0e commit 714c912
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/transformers/securityDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ module.exports = securityDefinitions => {
+ `${securityDefinitions[type][value][scope].replace(/[\r\n]/g, ' ')}|`);
});
} else if (value !== 'type' && securityDefinitions[type][value].replace) {
res.push(`|${nameResolver[value]}|`
+ `${securityDefinitions[type][value].replace(/[\r\n]/g, ' ')}|`);
let key = nameResolver[value];
if (key === undefined) {
if (value.match(/^x-/i)) {
key = value;
} else {
return;
}
}
res.push(`|${key}|${securityDefinitions[type][value].replace(/[\r\n]/g, ' ')}|`);
}
});
res.push('');
Expand Down
13 changes: 13 additions & 0 deletions tests/transformers/securityDefinitions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ describe('Security definitions', () => {
const res = transformSecurituDefinitions(fixture);
expect(res).to.exist;
});
it('Should ignore undefined keys unless it is prefixed with x-', () => {
const fixture = {
'complex-structure': {
type: 'apiKey',
name: 'Name',
'x-special-key': 'Special key',
'unknown-key': 'Uknown key',
}
};
const result = transformSecurituDefinitions(fixture);
expect(result.match(/undefined/ig)).to.be.null;
expect(result.match(/x-special-key/ig)).to.be.not.null;
});
});

0 comments on commit 714c912

Please sign in to comment.