Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate error reason when parameter is required but not present #453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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