@@ -85,6 +85,7 @@ class VisitorNode<NodeType extends VisitorTypes> {
8585 public type : NodeType ,
8686 public object : VisitorObjects [ NodeType ] | undefined ,
8787 public path : string [ ] ,
88+ public pathFromParent ?: string [ ] ,
8889 ) { }
8990
9091 static fromParent <
@@ -130,7 +131,14 @@ class VisitorNode<NodeType extends VisitorTypes> {
130131 } ;
131132
132133 forEachValue ( dict , ( value , key ) => {
133- nodes . push ( new VisitorNode ( type , value , [ ...parent . path , dictPath , key ] ) ) ;
134+ nodes . push (
135+ new VisitorNode (
136+ type ,
137+ value ,
138+ [ ...parent . path , dictPath , key ] ,
139+ [ dictPath , key ] ,
140+ ) ,
141+ ) ;
134142 } ) ;
135143
136144 return nodes ;
@@ -159,7 +167,12 @@ class VisitorNode<NodeType extends VisitorTypes> {
159167
160168 array . forEach ( ( value , index ) => {
161169 nodes . push (
162- new VisitorNode ( type , value , [ ...parent . path , arrayPath , `${ index } ` ] ) ,
170+ new VisitorNode (
171+ type ,
172+ value ,
173+ [ ...parent . path , arrayPath , `${ index } ` ] ,
174+ [ arrayPath , `${ index } ` ] ,
175+ ) ,
163176 ) ;
164177 } ) ;
165178
@@ -230,12 +243,17 @@ export class SchemaPreprocessor<
230243
231244 // Resolve reference object in parent, then process again with resolved schema
232245 // As every object (aka schema) is 'pass-by-reference', this will update the actual apiDoc.
233- const lastPathComponent = node . path [ node . path . length - 1 ] ;
234- if ( isInteger ( lastPathComponent ) ) {
235- const arrayName = node . path [ node . path . length - 2 ] ;
236- const index = parseInt ( lastPathComponent ) ;
237- parent . object [ arrayName ] [ index ] = resolvedObject ;
246+ if ( node . pathFromParent && node . pathFromParent . length > 0 ) {
247+ const pathLength = node . pathFromParent . length ;
248+
249+ let object = parent . object ;
250+ for ( let i = 0 ; i < pathLength - 1 ; i ++ ) {
251+ object = object [ node . pathFromParent [ i ] ] ;
252+ }
253+
254+ object [ node . pathFromParent [ pathLength - 1 ] ] = resolvedObject ;
238255 } else {
256+ const lastPathComponent = node . path [ node . path . length - 1 ] ;
239257 parent . object [ lastPathComponent ] = resolvedObject ;
240258 }
241259
@@ -874,13 +892,18 @@ export class SchemaPreprocessor<
874892
875893 const children = [ ] ;
876894
895+ /*
896+ // TODO: Probably not correctly resolved in case of schema ref!!!
897+ // path calculation is taken from the old code
877898 children.push(
878899 new VisitorNode('schema', parent.object.schema, [
879900 ...parent.path.slice(0, parent.path.length - 1),
880901 parent.object.name,
881902 parent.object.in,
882903 ]),
883904 );
905+ */
906+ children . push ( VisitorNode . fromParent ( parent , 'schema' ) ) ;
884907 children . push (
885908 ...VisitorNode . fromParentDict ( parent , 'mediaType' , 'content' ) ,
886909 ) ;
0 commit comments