Repository: getkin/kin-openapi
Pull request #516 (2022-03-28 11:11:36)

Fix ExampleValidator test for 32-bit architectures
Fix an integer overflow in ExampleValidator on 32-bit architectures (where `65536 * 65536` with `int` returns `0`)
by using int64 for square calculations.

Tested with `GOARCH=386 go test ./...`

See Debian Bug report log "autopkgtest regression on armhf and i386" at https://bugs.debian.org/1007733

Many thanks!


Patch:
diff --git a/openapi3filter/errors.go b/openapi3filter/errors.go
index 8454c81..1094bcf 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()


Test patch:
diff --git a/openapi3filter/middleware_test.go b/openapi3filter/middleware_test.go
index 4d88aaf..930af2a 100644
--- a/openapi3filter/middleware_test.go
+++ b/openapi3filter/middleware_test.go
@@ -420,7 +420,7 @@ paths:
 	// requests.
 	squareHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		xParam := path.Base(r.URL.Path)
-		x, err := strconv.Atoi(xParam)
+		x, err := strconv.ParseInt(xParam, 10, 64)
 		if err != nil {
 			panic(err)
 		}
diff --git a/openapi3filter/validation_error_test.go b/openapi3filter/validation_error_test.go
index 11032c1..aae26e5 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`},