Skip to content

Commit 6013125

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 6013125

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

parameters/header_parameters.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ func (v *paramValidator) ValidateHeaderParamsWithPathItem(request *http.Request,
183183
validationErrors = append(validationErrors, ValidateSingleParameterSchema(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: 9 additions & 0 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
@@ -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:
@@ -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:
@@ -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:

parameters/query_parameters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (v *paramValidator) validateSimpleParam(sch *base.Schema, rawParam string,
282282
}
283283
}
284284

285-
return ValidateSingleParameterSchemaWithPath(
285+
return ValidateSingleParameterSchema(
286286
sch,
287287
parsedParam,
288288
"Query parameter",

parameters/validate_parameter.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ func ValidateSingleParameterSchema(
3333
validationType string,
3434
subValType string,
3535
o *config.ValidationOptions,
36-
) (validationErrors []*errors.ValidationError) {
37-
return ValidateSingleParameterSchemaWithPath(schema, rawObject, entity, reasonEntity, name, validationType, subValType, o, "", "")
38-
}
39-
40-
func ValidateSingleParameterSchemaWithPath(
41-
schema *base.Schema,
42-
rawObject any,
43-
entity string,
44-
reasonEntity string,
45-
name string,
46-
validationType string,
47-
subValType string,
48-
o *config.ValidationOptions,
4936
pathTemplate string,
5037
operation string,
5138
) (validationErrors []*errors.ValidationError) {

parameters/validate_parameter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
func Test_ForceCompilerError(t *testing.T) {
2020
// Try to force a panic
21-
result := ValidateSingleParameterSchema(nil, nil, "", "", "", "", "", nil)
21+
result := ValidateSingleParameterSchema(nil, nil, "", "", "", "", "", nil, "", "")
2222

2323
// Ideally this would result in an error response, current behavior swallows the error
2424
require.Empty(t, result)

0 commit comments

Comments
 (0)