Skip to content

Commit 1b79472

Browse files
authored
Merge pull request #723 from postmanlabs/feature/fix-typeerror
Fixed issue where for certain path segments, collection generation failed.
2 parents c811736 + ce52c9f commit 1b79472

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/schemaUtils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,11 @@ module.exports = {
651651
// adding children for the nodes in the trie
652652
// start at the top-level and do a DFS
653653
for (i = 0; i < pathLength; i++) {
654-
if (!currentNode.children[currentPath[i]]) {
654+
/**
655+
* Use hasOwnProperty to determine if property exists as certain JS fuction are present
656+
* as part of each object. e.g. `constructor`.
657+
*/
658+
if (!(typeof currentNode.children === 'object' && currentNode.children.hasOwnProperty(currentPath[i]))) {
655659
// if the currentPath doesn't already exist at this node,
656660
// add it as a folder
657661
currentNode.addChildren(currentPath[i], new Node({

test/unit/util.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,45 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
686686

687687
done();
688688
});
689+
690+
it('should generate trie for definition with certain path segment same as JS object function names correctly',
691+
function (done) {
692+
var openapi = {
693+
'openapi': '3.0.0',
694+
'info': {
695+
'version': '1.0.0',
696+
'title': 'Swagger Petstore',
697+
'license': {
698+
'name': 'MIT'
699+
}
700+
},
701+
'servers': [
702+
{
703+
'url': 'http://petstore.swagger.io/{v1}'
704+
}
705+
],
706+
'paths': {
707+
'/constructor/v3/update-constructor': {
708+
'get': {
709+
'summary': 'List all pets',
710+
'operationId': 'listPets',
711+
'responses': {
712+
'200': {
713+
'description': 'An paged array of pets'
714+
}
715+
}
716+
}
717+
}
718+
}
719+
},
720+
output = SchemaUtils.generateTrieFromPaths(openapi),
721+
root = output.tree.root;
722+
723+
expect(root.children).to.be.an('object').that.has.all.keys('constructor');
724+
expect(root.children.constructor.requestCount).to.equal(1);
725+
726+
done();
727+
});
689728
});
690729

691730
describe('convertPathVariables', function() {

0 commit comments

Comments
 (0)