From ca21ef50e5232035978b7cee351f2f06416d5247 Mon Sep 17 00:00:00 2001 From: K Zhang Date: Wed, 30 Mar 2022 09:52:12 -0400 Subject: [PATCH] RequestError Error() does not include reason if it is the same as err (#517) Co-authored-by: Kanda --- openapi3filter/errors.go | 2 +- openapi3filter/validation_error_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openapi3filter/errors.go b/openapi3filter/errors.go index 8454c817f..1094bcf75 100644 --- a/openapi3filter/errors.go +++ b/openapi3filter/errors.go @@ -22,7 +22,7 @@ var _ interface{ Unwrap() error } = RequestError{} func (err *RequestError) Error() string { reason := err.Reason if e := err.Err; e != nil { - if len(reason) == 0 { + if len(reason) == 0 || reason == e.Error() { reason = e.Error() } else { reason += ": " + e.Error() diff --git a/openapi3filter/validation_error_test.go b/openapi3filter/validation_error_test.go index 11032c141..aae26e56b 100644 --- a/openapi3filter/validation_error_test.go +++ b/openapi3filter/validation_error_test.go @@ -181,7 +181,7 @@ func getValidationTests(t *testing.T) []*validationTest { }, wantErrParam: "status", wantErrParamIn: "query", - wantErrBody: `parameter "status" in query has an error: value is required but missing: value is required but missing`, + wantErrBody: `parameter "status" in query has an error: value is required but missing`, wantErrReason: "value is required but missing", wantErrResponse: &ValidationError{Status: http.StatusBadRequest, Title: `parameter "status" in query is required`}, @@ -214,7 +214,7 @@ func getValidationTests(t *testing.T) []*validationTest { }, wantErrParam: "tags", wantErrParamIn: "query", - wantErrBody: `parameter "tags" in query has an error: empty value is not allowed: empty value is not allowed`, + wantErrBody: `parameter "tags" in query has an error: empty value is not allowed`, wantErrReason: "empty value is not allowed", wantErrResponse: &ValidationError{Status: http.StatusBadRequest, Title: `parameter "tags" in query is not allowed to be empty`}, @@ -444,7 +444,7 @@ func getValidationTests(t *testing.T) []*validationTest { }, wantErrParam: "petId", wantErrParamIn: "path", - wantErrBody: `parameter "petId" in path has an error: value is required but missing: value is required but missing`, + wantErrBody: `parameter "petId" in path has an error: value is required but missing`, wantErrReason: "value is required but missing", wantErrResponse: &ValidationError{Status: http.StatusBadRequest, Title: `parameter "petId" in path is required`},