Skip to content

Commit

Permalink
openapi3filter: Simplify ValidateRequest implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Dec 11, 2024
1 parent 793b28d commit c6a2b92
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions openapi3filter/validate_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var ErrInvalidEmptyValue = errors.New("empty value is not allowed")
//
// Note: One can tune the behavior of uniqueItems: true verification
// by registering a custom function with openapi3.RegisterArrayUniqueItemsChecker
func ValidateRequest(ctx context.Context, input *RequestValidationInput) (err error) {
func ValidateRequest(ctx context.Context, input *RequestValidationInput) error {
var me openapi3.MultiError

options := input.Options
Expand All @@ -49,10 +49,10 @@ func ValidateRequest(ctx context.Context, input *RequestValidationInput) (err er
security = &route.Spec.Security
}
if security != nil {
if err = ValidateSecurityRequirements(ctx, input, *security); err != nil && !options.MultiError {
return
}
if err != nil {
if err := ValidateSecurityRequirements(ctx, input, *security); err != nil {
if !options.MultiError {
return err
}
me = append(me, err)
}
}
Expand All @@ -66,10 +66,10 @@ func ValidateRequest(ctx context.Context, input *RequestValidationInput) (err er
}
}

if err = ValidateParameter(ctx, input, parameter); err != nil && !options.MultiError {
return
}
if err != nil {
if err := ValidateParameter(ctx, input, parameter); err != nil {
if !options.MultiError {
return err
}
me = append(me, err)
}
}
Expand All @@ -79,29 +79,29 @@ func ValidateRequest(ctx context.Context, input *RequestValidationInput) (err er
if options.ExcludeRequestQueryParams && parameter.Value.In == openapi3.ParameterInQuery {
continue
}
if err = ValidateParameter(ctx, input, parameter.Value); err != nil && !options.MultiError {
return
}
if err != nil {
if err := ValidateParameter(ctx, input, parameter.Value); err != nil {
if !options.MultiError {
return err
}
me = append(me, err)
}
}

// RequestBody
requestBody := operation.RequestBody
if requestBody != nil && !options.ExcludeRequestBody {
if err = ValidateRequestBody(ctx, input, requestBody.Value); err != nil && !options.MultiError {
return
}
if err != nil {
if err := ValidateRequestBody(ctx, input, requestBody.Value); err != nil {
if !options.MultiError {
return err
}
me = append(me, err)
}
}

if len(me) > 0 {
return me
}
return
return nil
}

// appendToQueryValues adds to query parameters each value in the provided slice
Expand Down

0 comments on commit c6a2b92

Please sign in to comment.