Skip to content

Commit

Permalink
fix: duplicate error reason when parameter is required but not present (
Browse files Browse the repository at this point in the history
  • Loading branch information
NickUfer authored Dec 2, 2021
1 parent eb43e20 commit f7c80fe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion openapi3filter/validate_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func ValidateParameter(ctx context.Context, input *RequestValidationInput, param
// Validate a parameter's value.
if value == nil {
if parameter.Required {
return &RequestError{Input: input, Parameter: parameter, Reason: ErrInvalidRequired.Error(), Err: ErrInvalidRequired}
return &RequestError{Input: input, Parameter: parameter, Err: ErrInvalidRequired}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion openapi3filter/validation_error_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func convertBasicRequestError(e *RequestError) *ValidationError {
}

func convertErrInvalidRequired(e *RequestError) *ValidationError {
if e.Reason == ErrInvalidRequired.Error() && e.Parameter != nil {
if e.Err == ErrInvalidRequired && e.Parameter != nil {
return &ValidationError{
Status: http.StatusBadRequest,
Title: fmt.Sprintf("parameter %q in %s is required", e.Parameter.Name, e.Parameter.In),
Expand Down
4 changes: 2 additions & 2 deletions openapi3filter/validation_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func getValidationTests(t *testing.T) []*validationTest {
},
wantErrParam: "status",
wantErrParamIn: "query",
wantErrReason: ErrInvalidRequired.Error(),
wantErrBody: `parameter "status" in query has an error: value is required but missing`,
wantErrResponse: &ValidationError{Status: http.StatusBadRequest,
Title: `parameter "status" in query is required`},
},
Expand Down Expand Up @@ -424,7 +424,7 @@ func getValidationTests(t *testing.T) []*validationTest {
},
wantErrParam: "petId",
wantErrParamIn: "path",
wantErrReason: ErrInvalidRequired.Error(),
wantErrBody: `parameter "petId" in path has an error: value is required but missing`,
wantErrResponse: &ValidationError{Status: http.StatusBadRequest,
Title: `parameter "petId" in path is required`},
},
Expand Down

0 comments on commit f7c80fe

Please sign in to comment.