Skip to content

Commit 8b3753a

Browse files
nevivurnMarcin Romaszewicz
andauthored
Fix broken build due to kin backwards-incompatible change (#322)
Co-authored-by: Marcin Romaszewicz <47459980+deepmap-marcinr@users.noreply.github.com>
1 parent 672b09e commit 8b3753a

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

oapi_validate.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323

2424
"github.com/getkin/kin-openapi/openapi3"
2525
"github.com/getkin/kin-openapi/openapi3filter"
26+
"github.com/getkin/kin-openapi/routers"
27+
"github.com/getkin/kin-openapi/routers/legacy"
2628
"github.com/labstack/echo/v4"
2729
echomiddleware "github.com/labstack/echo/v4/middleware"
2830
)
@@ -65,7 +67,11 @@ type Options struct {
6567

6668
// Create a validator from a swagger object, with validation options
6769
func OapiRequestValidatorWithOptions(swagger *openapi3.Swagger, options *Options) echo.MiddlewareFunc {
68-
router := openapi3filter.NewRouter().WithSwagger(swagger)
70+
router, err := legacy.NewRouter(swagger)
71+
if err != nil {
72+
panic(err)
73+
}
74+
6975
skipper := getSkipperFromOptions(options)
7076
return func(next echo.HandlerFunc) echo.HandlerFunc {
7177
return func(c echo.Context) error {
@@ -84,14 +90,14 @@ func OapiRequestValidatorWithOptions(swagger *openapi3.Swagger, options *Options
8490

8591
// This function is called from the middleware above and actually does the work
8692
// of validating a request.
87-
func ValidateRequestFromContext(ctx echo.Context, router *openapi3filter.Router, options *Options) error {
93+
func ValidateRequestFromContext(ctx echo.Context, router routers.Router, options *Options) error {
8894
req := ctx.Request()
89-
route, pathParams, err := router.FindRoute(req.Method, req.URL)
95+
route, pathParams, err := router.FindRoute(req)
9096

9197
// We failed to find a matching route for the request.
9298
if err != nil {
9399
switch e := err.(type) {
94-
case *openapi3filter.RouteError:
100+
case *routers.RouteError:
95101
// We've got a bad request, the path requested doesn't match
96102
// either server, or path, or something.
97103
return echo.NewHTTPError(http.StatusBadRequest, e.Reason)

0 commit comments

Comments
 (0)