Skip to content

Commit 88e9639

Browse files
committed
Revert "Fix broken build due to kin backwards-incompatible change (#322)"
This reverts commit 88f937a7166a1e3603e3ec96e57e45af7a998373. The kin legacy routers force pulling in kin-openapi@0.52.0 which requires Go 1.16
1 parent 8b3753a commit 88e9639

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

oapi_validate.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ 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"
2826
"github.com/labstack/echo/v4"
2927
echomiddleware "github.com/labstack/echo/v4/middleware"
3028
)
@@ -67,11 +65,7 @@ type Options struct {
6765

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

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

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

0 commit comments

Comments
 (0)