@@ -4,28 +4,14 @@ 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 = 2 ;
7+ const MAX_DEPTH = 2 ; // Only first callback level is supported
88
99type PathContext = {
1010 path : string ;
1111 templateParams : Set < string > ;
1212 definedParams : Set < string > ;
1313} ;
1414
15- type OperationHandlers = {
16- enter : ( ) => void ;
17- leave : ( op : unknown , ctx : UserContext ) => void ;
18- Parameter : ( parameter : Oas2Parameter | Oas3Parameter , ctx : UserContext ) => void ;
19- Callback ?: {
20- PathItem : {
21- enter : ( node : object , ctx : UserContext ) => void ;
22- leave : ( ) => void ;
23- Parameter : ( parameter : Oas2Parameter | Oas3Parameter , ctx : UserContext ) => void ;
24- Operation : OperationHandlers ;
25- } ;
26- } ;
27- } ;
28-
2915export const PathParamsDefined : Oas3Rule | Oas2Rule = ( ) => {
3016 const pathContext = { current : null as PathContext | null } ;
3117 const currentOperationParams = new Set < string > ( ) ;
@@ -76,52 +62,30 @@ const createPathItemParameterHandler = (
7662 }
7763} ;
7864
79- const createEmptyOperationHandlers = ( maxDepth : number ) : OperationHandlers => {
80- let warningReported = false ;
81-
82- const reportMaxDepthWarning = (
83- report : UserContext [ 'report' ] ,
84- location : UserContext [ 'location' ]
85- ) => {
86- if ( ! warningReported ) {
87- warningReported = true ;
88- report ( {
89- message : `Maximum callback nesting depth (${ maxDepth } ) reached. Path parameter validation is limited beyond this depth to prevent infinite recursion.` ,
90- location : location ,
91- } ) ;
92- }
93- } ;
94-
95- return {
96- enter : ( ) => { } ,
97- leave ( _op : unknown , { report, location } : UserContext ) {
98- reportMaxDepthWarning ( report , location ) ;
99- } ,
100- Parameter : ( ) => { } ,
101- Callback : {
102- PathItem : {
103- enter ( _ : object , { report, location } : UserContext ) {
104- reportMaxDepthWarning ( report , location ) ;
105- } ,
106- leave : ( ) => { } ,
107- Parameter : ( ) => { } ,
108- Operation : {
109- enter : ( ) => { } ,
110- leave : ( ) => { } ,
111- Parameter : ( ) => { } ,
112- } ,
113- } ,
114- } ,
115- } ;
116- } ;
117-
11865const createOperationHandlers = (
11966 pathContext : { current : PathContext | null } ,
12067 currentOperationParams : Set < string > ,
12168 depth = 0
122- ) : OperationHandlers => {
69+ ) => {
70+ const reportMaxDepthWarning = (
71+ report : UserContext [ 'report' ] ,
72+ location : UserContext [ 'location' ] ,
73+ depth : number
74+ ) => {
75+ report ( {
76+ message : `Maximum callback nesting depth (${ depth } ) reached. Path parameter validation is limited beyond this depth to prevent infinite recursion.` ,
77+ location : location ,
78+ } ) ;
79+ } ;
12380 if ( depth >= MAX_DEPTH ) {
124- return createEmptyOperationHandlers ( MAX_DEPTH ) ;
81+ return {
82+ enter : ( ) => { } ,
83+ leave : ( _op : unknown , { report, location } : UserContext ) => {
84+ reportMaxDepthWarning ( report , location , depth ) ;
85+ } ,
86+ Parameter : ( ) => { } ,
87+ Callback : undefined ,
88+ } ;
12589 }
12690
12791 const createCallbackPathItem = ( ) => {
0 commit comments