oapi-codegen
oapi-codegen copied to clipboard
gin: included middleware cannot abort request
For Gin generated code, when supplying middleware:
RegisterHandlersWithOptions(router, handler, GinServerOptions{
Middlewares: []MiddlewareFunc{
auth.AuthenticateAndAuthorize,
},
})
A request cannot be abort by middleware, the request is fully being handled.. which mean authentication middleware cannot abort a request for example.
(@stephen-opal noticed the issue in initial pull request: https://github.com/deepmap/oapi-codegen/pull/385#discussion_r655001461)
Any chance this will be getting resolved?
For the time being you can just take my modified gin template files from #926 and use them as custom templates during generation as described here: https://github.com/deepmap/oapi-codegen#making-changes-to-code-generation
I just put them in my project directory:
Then I call oapi-codegen -generate gin -templates scripts/oapi-codegen-templates/ -o "gen/openapi/openapi_api.gen.go" -package "rest_service" "api/openapi/rest_service.yaml"
This should be resolved by #914, @deepmap-marcinr probably good to close this :)