oapi-codegen
oapi-codegen copied to clipboard
Using per-endpoint middleware
At the moment when RegisterHandlersWithBaseURL
is generated there is no way to specify per-handler middleware. In our use case we need to use some middleware's on per-handler bases rather than global ones.
The EchoRouter
interface has a 3rd param to pass on the middleware:
type EchoRouter interface {
CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}
However there's no way to let RegisterHandlersWithBaseURL
know about it. Is there any way to do it without having a global middleware which has to check whether it can be run for the given request?
Hey @screwyprof there is a started solution in 462
Hi @valensto. Thanks for letting me know. Are there any plans to support echo
?
I think #462 is abandoned, i started another take on this issue here: #947
Apologies for missing this folks.
The proposals in #462 and #947 look like a reasonable solution - at a first glance. I can try and come back to this early next year when I've got a bit more time to review + possibly propose some changes.
Related: https://github.com/getkin/kin-openapi/issues/825