per-operation middleware in Echo#2353
Conversation
Closes: oapi-codegen#518 Add a RegisterHandlersWithOptions to both Echo backends, which takes a BaseUrl and a map of OperationMiddlewares, keyed by spec OperationId. Only Echo supports registering per-op middleware, so this change is only for Echo.
Greptile SummaryThis PR implements per-operation middleware support for both Echo v4 and Echo v5 backends by introducing
Confidence Score: 3/5Mostly safe to merge, but the unrelated binding-change drift in the echo/v4 petstore example file needs to be resolved first. The core template change and regression test are well-implemented, but a P1 finding — unrelated parameter-binding changes in examples/petstore-expanded/echo/api/petstore-server.gen.go absent from the echo-v5 counterpart — indicates the file was regenerated with a different toolchain and will likely cause a CI make generate diff failure. examples/petstore-expanded/echo/api/petstore-server.gen.go — contains binding-call changes unrelated to this PR that are not present in the echo-v5 equivalent.
|
| Filename | Overview |
|---|---|
| examples/petstore-expanded/echo/api/petstore-server.gen.go | Contains expected RegisterHandlersWithOptions changes plus unrelated binding-call changes absent from the echo-v5 equivalent; looks regenerated with a different toolchain. |
| examples/petstore-expanded/echo-v5/api/petstore-server.gen.go | Only middleware-related changes; no unrelated drift; clean regeneration. |
| pkg/codegen/templates/echo/echo-register.tmpl | Adds RegisterHandlersOptions with BaseURL+OperationMiddlewares and refactors registration into RegisterHandlersWithOptions; correct and nil-map-safe. |
| pkg/codegen/templates/echo/v5/echo-register.tmpl | Identical change to the v4 template; clean and correct. |
| pkg/codegen/operations.go | Adds MiddlewareKey() to OperationDefinition; correct spec-ID-first with normalized-ID fallback; no issues. |
| internal/test/issues/issue-518/issue518_test.go | Good regression test covering per-op middleware, no-operationId fallback, and backward compat. |
| internal/test/issues/issue-518/issue518.gen.go | New generated fixture; correctly uses raw spec IDs and normalized fallback as middleware keys. |
Comments Outside Diff (1)
-
examples/petstore-expanded/echo/api/petstore-server.gen.go, line 63-73 (link)Unrelated drift in regenerated file
examples/petstore-expanded/echo/api/petstore-server.gen.gocontains parameter-binding changes unrelated to this PR's stated goal of per-operation middleware. Specifically, calls toBindQueryParameterhave been replaced withBindQueryParameterWithOptions(gainingType/Formatfields), andBindStyledParameterWithOptionscall sites gain the same extra fields. These changes do not appear in the otherwise-analogous echo-v5 petstore file, suggesting this file was regenerated with a local toolchain that includes additional unreleased changes. Per the project policy, CI fails whenmake generateproduces a diff — if the intended generator does not yet emit these binding changes, CI will fail on this file.
Reviews (1): Last reviewed commit: "per-operation middleware in Echo" | Re-trigger Greptile
@greptileai - this is because for some reason, the petstore boilerplate hasn't successfully regenerated into a while. Our "make generate" target bypasses it. I will fix that in a separate commit. This is correct. |
|
Got it, thanks for the context. If the petstore example is intentionally excluded from Tip: You can give me more context with .greptile/rules.md so I get this right next time. |
Closes: #518
Add a RegisterHandlersWithOptions to both Echo backends, which takes a BaseUrl and a map of OperationMiddlewares, keyed by spec OperationId. Only Echo supports registering per-op middleware, so this change is only for Echo.