@@ -4,7 +4,7 @@ import type { Oas3Parameter } from '../../typings/openapi.js';
44import type { UserContext } from '../../walk.js' ;
55
66const pathRegex = / \{ ( [ a - z A - Z 0 - 9 _ . - ] + ) \} + / g;
7- const MAX_DEPTH = 4 ;
7+ const MAX_DEPTH = 2 ;
88
99type PathContext = {
1010 path : string ;
@@ -16,7 +16,7 @@ type OperationHandlers = {
1616 enter : ( ) => void ;
1717 leave : ( op : unknown , ctx : UserContext ) => void ;
1818 Parameter : ( parameter : Oas2Parameter | Oas3Parameter , ctx : UserContext ) => void ;
19- Callback : {
19+ Callback ? : {
2020 PathItem : {
2121 enter : ( node : object , ctx : UserContext ) => void ;
2222 leave : ( ) => void ;
@@ -28,7 +28,7 @@ type OperationHandlers = {
2828
2929export const PathParamsDefined : Oas3Rule | Oas2Rule = ( ) => {
3030 const pathContext = { current : null as PathContext | null } ;
31- const operationParams = { current : null as Set < string > | null } ;
31+ const currentOperationParams = new Set < string > ( ) ;
3232
3333 return {
3434 PathItem : {
@@ -41,7 +41,7 @@ export const PathParamsDefined: Oas3Rule | Oas2Rule = () => {
4141 Parameter ( parameter : Oas2Parameter | Oas3Parameter , { report, location } : UserContext ) {
4242 createPathItemParameterHandler ( parameter , pathContext , report , location ) ;
4343 } ,
44- Operation : createOperationHandlers ( pathContext , operationParams ) ,
44+ Operation : createOperationHandlers ( pathContext , currentOperationParams ) ,
4545 } ,
4646 } ;
4747} ;
@@ -109,16 +109,15 @@ const createEmptyOperationHandlers = (maxDepth: number): OperationHandlers => {
109109 enter : ( ) => { } ,
110110 leave : ( ) => { } ,
111111 Parameter : ( ) => { } ,
112- Callback : { } ,
113112 } ,
114113 } ,
115114 } ,
116- } as unknown as OperationHandlers ;
115+ } ;
117116} ;
118117
119118const createOperationHandlers = (
120119 pathContext : { current : PathContext | null } ,
121- operationParams : { current : Set < string > | null } ,
120+ currentOperationParams : Set < string > ,
122121 depth = 0
123122) : OperationHandlers => {
124123 if ( depth >= MAX_DEPTH ) {
@@ -140,23 +139,23 @@ const createOperationHandlers = (
140139 createPathItemParameterHandler ( parameter , pathContext , report , location ) ;
141140 } ,
142141 get Operation ( ) {
143- return createOperationHandlers ( pathContext , operationParams , depth + 1 ) ;
142+ return createOperationHandlers ( pathContext , currentOperationParams , depth + 1 ) ;
144143 } ,
145144 } ;
146145 } ;
147146
148147 return {
149148 enter ( ) {
150- operationParams . current = new Set ( ) ;
149+ currentOperationParams = new Set ( ) ;
151150 } ,
152151 leave ( _op : unknown , { report, location } : UserContext ) {
153- if ( ! pathContext . current || ! operationParams . current ) return ;
152+ if ( ! pathContext . current || ! currentOperationParams ) return ;
154153
155- collectPathParamsFromOperation ( _op , operationParams . current ) ;
154+ collectPathParamsFromOperation ( _op , currentOperationParams ) ;
156155
157156 validateRequiredPathParams (
158157 pathContext . current . templateParams ,
159- operationParams . current ,
158+ currentOperationParams ,
160159 pathContext . current . definedParams ,
161160 pathContext . current . path ,
162161 report ,
@@ -165,10 +164,10 @@ const createOperationHandlers = (
165164 } ,
166165 Parameter ( parameter : Oas2Parameter | Oas3Parameter , { report, location } : UserContext ) {
167166 if ( parameter . in === 'path' && parameter . name && pathContext . current ) {
168- if ( ! operationParams . current ) {
169- operationParams . current = new Set ( ) ;
167+ if ( ! currentOperationParams ) {
168+ currentOperationParams = new Set ( ) ;
170169 }
171- operationParams . current . add ( parameter . name ) ;
170+ currentOperationParams . add ( parameter . name ) ;
172171 validatePathParameter (
173172 parameter . name ,
174173 pathContext . current . templateParams ,
0 commit comments