@@ -9,9 +9,10 @@ import {
9
9
ArraySlice ,
10
10
ObjectElement ,
11
11
isArrayElement ,
12
+ includesClasses ,
12
13
} from '@swagger-api/apidom-core' ;
13
14
import { CompletionItem } from 'vscode-languageserver-types' ;
14
- import { test , resolve } from 'openapi-path-templating' ;
15
+ import { test , resolve , parse } from 'openapi-path-templating' ;
15
16
16
17
// eslint-disable-next-line import/no-cycle
17
18
import {
@@ -1068,4 +1069,39 @@ export const standardLinterfunctions: FunctionItem[] = [
1068
1069
return true ;
1069
1070
} ,
1070
1071
} ,
1072
+ {
1073
+ functionName : 'apilintOpenAPIParameterInPathTemplate' ,
1074
+ function : ( element : Element ) => {
1075
+ if ( element . element === 'parameter' ) {
1076
+ const parameterLocation = toValue ( ( element as ObjectElement ) . get ( 'in' ) ) ;
1077
+
1078
+ if ( parameterLocation !== 'path' ) return true ;
1079
+
1080
+ const isInPathItemElement =
1081
+ isArrayElement ( element . parent ) &&
1082
+ includesClasses ( [ 'path-item-parameters' ] , element . parent ) ;
1083
+
1084
+ if ( ! isInPathItemElement ) return true ;
1085
+
1086
+ const pathItemElement = element . parent . parent . parent ;
1087
+ const isPathItemPartOfPathTemplating = isStringElement ( pathItemElement . meta . get ( 'path' ) ) ;
1088
+
1089
+ if ( ! isPathItemPartOfPathTemplating ) return true ;
1090
+
1091
+ const pathTemplate = toValue ( pathItemElement . meta . get ( 'path' ) ) ;
1092
+ const parameterName = toValue ( ( element as ObjectElement ) . get ( 'name' ) ) ;
1093
+
1094
+ const parseResult = parse ( pathTemplate ) ;
1095
+ if ( ! parseResult . result . success ) return true ;
1096
+
1097
+ const parts : [ string , string ] [ ] = [ ] ;
1098
+ parseResult . ast . translate ( parts ) ;
1099
+
1100
+ return parts . some (
1101
+ ( [ name , value ] ) => name === 'template-expression-param-name' && value === parameterName ,
1102
+ ) ;
1103
+ }
1104
+ return true ;
1105
+ } ,
1106
+ } ,
1071
1107
] ;
0 commit comments