From e592981d9d8b47963248f3be5fb2858ef4682982 Mon Sep 17 00:00:00 2001 From: Florent CHAUVEAU Date: Sun, 5 Jan 2025 14:46:24 +0100 Subject: [PATCH] Fixes #12 return http.StatusMethodNotAllowed when appropriate --- oapi_validate.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oapi_validate.go b/oapi_validate.go index 907855b..f937ae1 100644 --- a/oapi_validate.go +++ b/oapi_validate.go @@ -118,6 +118,10 @@ func ValidateRequestFromContext(ctx echo.Context, router routers.Router, options if err != nil { switch e := err.(type) { case *routers.RouteError: + // The path may exist on the server, but the method is not allowed. + if errors.Is(e, routers.ErrMethodNotAllowed) { + return echo.NewHTTPError(http.StatusMethodNotAllowed, e.Reason) + } // We've got a bad request, the path requested doesn't match // either server, or path, or something. return echo.NewHTTPError(http.StatusNotFound, e.Reason)