oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

gin: included middleware cannot abort request

Open erikbos opened this issue 3 years ago • 2 comments

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)

erikbos avatar Nov 17 '21 22:11 erikbos

Any chance this will be getting resolved?

tomsharratt avatar Feb 20 '22 20:02 tomsharratt

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: image

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"

re-cheid avatar Jan 17 '23 07:01 re-cheid

This should be resolved by #914, @deepmap-marcinr probably good to close this :)

alexstojda avatar Jun 20 '23 16:06 alexstojda