@@ -208,20 +208,6 @@ func (pp PathParameters) RunRule(nodes []*yaml.Node, context model.RuleFunctionC
208
208
continue
209
209
}
210
210
if isVerb (r ) {
211
- if len (topLevelParams ) <= 0 {
212
- if verbLevelParams [r ] == nil {
213
- for pe := range pathElements {
214
- err := fmt .Sprintf ("`%s` must define parameter `%s` as expected by path `%s`" ,
215
- strings .ToUpper (r ), pe , currentPath )
216
- res := model .BuildFunctionResultString (err )
217
- res .StartNode = startNode
218
- res .EndNode = endNode
219
- res .Path = fmt .Sprintf ("$.paths['%s'].%s" , currentPath , r )
220
- res .Rule = context .Rule
221
- results = append (results , res )
222
- }
223
- }
224
- }
225
211
pp .ensureAllExpectedParamsInPathAreDefined (currentPath , allPathParams ,
226
212
pathElements , & results , startNode , endNode , context , r )
227
213
}
@@ -291,25 +277,22 @@ func (pp PathParameters) ensureAllDefinedPathParamsAreUsedInPath(path string, al
291
277
func (pp PathParameters ) ensureAllExpectedParamsInPathAreDefined (path string , allPathParams map [string ]map [string ][]string ,
292
278
pathElements map [string ]bool , results * []model.RuleFunctionResult , startNode , endNode * yaml.Node ,
293
279
context model.RuleFunctionContext , verb string ) {
294
- var top map [string ][]string
295
-
280
+ var topParams map [string ][]string
281
+ var verbParams map [ string ][] string
296
282
if allPathParams != nil {
297
- top = allPathParams ["top" ]
283
+ topParams = allPathParams ["top" ]
284
+ verbParams = allPathParams [verb ]
298
285
}
299
- for k , e := range allPathParams {
300
- if k == "top" {
301
- continue
302
- }
303
- for p := range pathElements {
304
- if ! pp .segmentExistsInPathParams (p , e , top ) {
305
- err := fmt .Sprintf ("`%s` must define parameter `%s` as expected by path `%s`" , strings .ToUpper (verb ), p , path )
306
- res := model .BuildFunctionResultString (err )
307
- res .StartNode = startNode
308
- res .EndNode = endNode
309
- res .Path = fmt .Sprintf ("$.paths['%s']" , path )
310
- res .Rule = context .Rule
311
- * results = append (* results , res )
312
- }
286
+ // For each expected path parameter, check the top and verb-level defined parameters
287
+ for p := range pathElements {
288
+ if ! pp .segmentExistsInPathParams (p , verbParams , topParams ) {
289
+ err := fmt .Sprintf ("`%s` must define parameter `%s` as expected by path `%s`" , strings .ToUpper (verb ), p , path )
290
+ res := model .BuildFunctionResultString (err )
291
+ res .StartNode = startNode
292
+ res .EndNode = endNode
293
+ res .Path = fmt .Sprintf ("$.paths['%s']" , path )
294
+ res .Rule = context .Rule
295
+ * results = append (* results , res )
313
296
}
314
297
}
315
298
}
0 commit comments