File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -651,7 +651,11 @@ module.exports = {
651
651
// adding children for the nodes in the trie
652
652
// start at the top-level and do a DFS
653
653
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 ] ) ) ) {
655
659
// if the currentPath doesn't already exist at this node,
656
660
// add it as a folder
657
661
currentNode . addChildren ( currentPath [ i ] , new Node ( {
Original file line number Diff line number Diff line change @@ -686,6 +686,45 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
686
686
687
687
done ( ) ;
688
688
} ) ;
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
+ } ) ;
689
728
} ) ;
690
729
691
730
describe ( 'convertPathVariables' , function ( ) {
You can’t perform that action at this time.
0 commit comments