Skip to content

Commit 831984f

Browse files
author
Michael Bonifacio
committed
Use ValidateSingleParameterSchemaWithPath consistently
- Updated path parameters to use ValidateSingleParameterSchemaWithPath - Updated header parameters to use ValidateSingleParameterSchemaWithPath - Now all parameter types (query, path, header, cookie) get full OpenAPI context - Ensures KeywordLocation is consistent across all parameter validation
1 parent 2141779 commit 831984f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

parameters/header_parameters.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,12 @@ func (v *paramValidator) ValidateHeaderParamsWithPathItem(request *http.Request,
180180
}
181181
if len(pType) == 0 {
182182
// validate schema as there is no type information.
183-
validationErrors = append(validationErrors, ValidateSingleParameterSchema(sch,
183+
validationErrors = append(validationErrors, ValidateSingleParameterSchemaWithPath(sch,
184184
param,
185185
p.Name,
186-
lowbase.SchemaLabel, p.Name, helpers.ParameterValidation, helpers.ParameterValidationHeader, v.options)...)
186+
lowbase.SchemaLabel, p.Name, helpers.ParameterValidation, helpers.ParameterValidationHeader, v.options,
187+
pathValue,
188+
operation)...)
187189
}
188190
} else {
189191
if p.Required != nil && *p.Required {

parameters/path_parameters.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func (v *paramValidator) ValidatePathParamsWithPathItem(request *http.Request, p
4747
submittedSegments := strings.Split(paths.StripRequestPath(request, v.document), helpers.Slash)
4848
pathSegments := strings.Split(pathValue, helpers.Slash)
4949

50+
// get the operation method for error reporting
51+
operation := strings.ToLower(request.Method)
52+
5053
// extract params for the operation
5154
params := helpers.ExtractParamsForOperation(request, pathItem)
5255
var validationErrors []*errors.ValidationError
@@ -176,7 +179,7 @@ func (v *paramValidator) ValidatePathParamsWithPathItem(request *http.Request, p
176179
break
177180
}
178181
validationErrors = append(validationErrors,
179-
ValidateSingleParameterSchema(
182+
ValidateSingleParameterSchemaWithPath(
180183
sch,
181184
decodedParamValue,
182185
"Path parameter",
@@ -185,6 +188,8 @@ func (v *paramValidator) ValidatePathParamsWithPathItem(request *http.Request, p
185188
helpers.ParameterValidation,
186189
helpers.ParameterValidationPath,
187190
v.options,
191+
pathValue,
192+
operation,
188193
)...)
189194

190195
case helpers.Integer:
@@ -199,7 +204,7 @@ func (v *paramValidator) ValidatePathParamsWithPathItem(request *http.Request, p
199204
enumCheck(rawParamValue)
200205
break
201206
}
202-
validationErrors = append(validationErrors, ValidateSingleParameterSchema(
207+
validationErrors = append(validationErrors, ValidateSingleParameterSchemaWithPath(
203208
sch,
204209
paramValueParsed,
205210
"Path parameter",
@@ -208,6 +213,8 @@ func (v *paramValidator) ValidatePathParamsWithPathItem(request *http.Request, p
208213
helpers.ParameterValidation,
209214
helpers.ParameterValidationPath,
210215
v.options,
216+
pathValue,
217+
operation,
211218
)...)
212219

213220
case helpers.Number:
@@ -222,7 +229,7 @@ func (v *paramValidator) ValidatePathParamsWithPathItem(request *http.Request, p
222229
enumCheck(rawParamValue)
223230
break
224231
}
225-
validationErrors = append(validationErrors, ValidateSingleParameterSchema(
232+
validationErrors = append(validationErrors, ValidateSingleParameterSchemaWithPath(
226233
sch,
227234
paramValueParsed,
228235
"Path parameter",
@@ -231,6 +238,8 @@ func (v *paramValidator) ValidatePathParamsWithPathItem(request *http.Request, p
231238
helpers.ParameterValidation,
232239
helpers.ParameterValidationPath,
233240
v.options,
241+
pathValue,
242+
operation,
234243
)...)
235244

236245
case helpers.Boolean:

0 commit comments

Comments
 (0)