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

Create a new context before passing it to strict handlers

Open m-vinc opened this issue 2 years ago • 3 comments
trafficstars

Hello, I don't know if this is relevant but when using the authenticate example and for example setting the current_user in the echo context after performing my authentication / authorization logic I can't retrieve it because only the context of the *http.Request is passed to the strict handler and not the echo context. I create a new context and inject the echo context with the key defined in the middleware package so in every strict handler we can now grab the echo context or the request handler by calling .Request() method on the echo context.

Well I don't know if this is clear, don't hesitate to tell me why this is a bad idea if this is one !

m-vinc avatar May 03 '23 15:05 m-vinc

You are right, this is a better way to pass request context downstream, however it is a breaking change. I do think it's worth creating a breakage to fix this.

deepmap-marcinr avatar May 08 '23 22:05 deepmap-marcinr

Hey, I'm not very sure about what you mean by breakage but I would be glad to do it if I can ! I use this context passing a lot in my projects so I would be happy to do the require work.

Also sorry for the late response !

m-vinc avatar Sep 24 '23 12:09 m-vinc

Either I'm missing something, or echo with StrictServer is hardly unusable without a custom template, since we cannot update the request's context in a middleware, or access Echo's context in the handlers. This PR feels critical to me.

Nivl avatar Apr 20 '25 06:04 Nivl