From 6db514f9745425119b8ba91a84118df900e74788 Mon Sep 17 00:00:00 2001 From: "Chris (CruftMaster)" Date: Thu, 27 Jun 2019 14:09:44 +0100 Subject: [PATCH] Returning the first line of the error (instead of the 'reason') --- pkg/middleware/oapi_validate.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/middleware/oapi_validate.go b/pkg/middleware/oapi_validate.go index a37360cd6a..8d994e70c4 100644 --- a/pkg/middleware/oapi_validate.go +++ b/pkg/middleware/oapi_validate.go @@ -19,6 +19,7 @@ import ( "fmt" "io/ioutil" "net/http" + "strings" "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/openapi3filter" @@ -116,7 +117,10 @@ func ValidateRequestFromContext(ctx echo.Context, router *openapi3filter.Router, switch e := err.(type) { case *openapi3filter.RequestError: // We've got a bad request - return echo.NewHTTPError(http.StatusBadRequest, e.Reason) + // Split up the verbose error by lines and return the first one + // openapi errors seem to be multi-line with a decent message on the first + errorLines := strings.Split(e.Error(), "\n") + return echo.NewHTTPError(http.StatusBadRequest, errorLines[0]) case *openapi3filter.SecurityRequirementsError: return echo.NewHTTPError(http.StatusForbidden, e.Error()) default: