@@ -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
6967func 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