feat: support echo v5#48
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
@jamietanna - what do you think, should we put echo V5 as a sub-module of echo-middleware or make a repo specifically for it? The middleware itself, for V4 and V5 is basically identical. I would love to see both just call through to shared code, but Go's module system makes it annoying since each sub-module requires its own git tag for each release to keep various tools happy, like Renovate. |
| @@ -0,0 +1,27 @@ | |||
| module github.com/oapi-codegen/echo-middleware/v5 | |||
|
|
|||
| go 1.26.2 | |||
There was a problem hiding this comment.
Echo works fine with Go 1.25.0 (https://github.com/labstack/echo/blob/v5/go.mod), so I think we should try not to get ahead of it too much to allow as many users as possible to use this package. Lots of people can't update to the latest Go version immediately due to all kinds of internal company bureaucracy.
jamietanna
left a comment
There was a problem hiding this comment.
I think child Go module is ok but not like this right now - if we do, it'll cause Go module versioning confusion, and can make it seem like it's v5 of this module - I'd say maybe echov5
I agree that a separate repo may not be ideal given the shared code
Also, if we are doing a submodule, this will require we change our release process (which is fine, but calling it out)
All **8 tests pass** cleanly with Go 1.25.0: | Test | Result | |------|--------| | `TestOapiRequestValidator` | ✅ PASS | | `TestOapiRequestValidatorWithOptionsMultiError` | ✅ PASS | | `TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler` | ✅ PASS | | `TestOapiRequestValidatorWithPrefix` | ✅ PASS | | `TestEncodedPathParams` | ✅ PASS | | `TestGetSkipperFromOptions` | ✅ PASS | | `ExampleOapiRequestValidatorWithOptions` | ✅ PASS | | `ExampleOapiRequestValidatorWithOptions_withErrorHandler` | ✅ PASS |
|
I have tried to apply some of your suggestion in the above commits.
|
|
In case we could tolerate some code redundancy, I could modify the PR with relevant changes . |
| const ( | ||
| EchoContextKey = "oapi-codegen/echo-context" | ||
| UserDataKey = "oapi-codegen/user-data" | ||
| ) |
There was a problem hiding this comment.
these two are the same as the ones in internal/validation/validate.go
could/should you use those directly?
| } | ||
|
|
||
| // Build validation context with Echo context and user data | ||
| requestContext := context.WithValue(context.Background(), validation.EchoContextKey, c) //nolint:staticcheck |
There was a problem hiding this comment.
is context.Background() correct here, or should it be c.Request().Context() ?
| var coder interface{ StatusCode() int } | ||
| if errors.As(err, &coder) { | ||
| return echo.NewHTTPError(coder.StatusCode(), err.Error()) | ||
| } |
There was a problem hiding this comment.
should there be a fallback for errors that don't happen to be either echo.HTTPError or coder?
closes #37