Bring all routers to parity with each other#2445
Conversation
The fiber v3 server template emitted per-operation security scope context values unconditionally, but the corresponding ...Scopes constants are only generated when compatibility.enable-auth-scopes-on-context is set. Under default configuration, any spec with security requirements therefore produced code referencing undefined identifiers and failed to compile. Gate the emission behind the flag, matching fiber v2 and every other server backend. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Greptile SummaryThis large batch PR audits all router backend templates for drift and applies a consistent set of fixes across chi, echo (v4/v5), fiber (v2/v3), gin, gorilla, iris, and stdhttp. It also adds a new fiber-v3 receiver template for webhook/callback support and introduces regression tests (cross-framework pass-through header roundtrip, iris middleware registration, fiber strict tests) that confirm the previously silent bugs.
Confidence Score: 5/5Safe to merge; all behavior changes are correctness fixes and the new receiver template follows the established pattern. Every template change has a matching regression test or generated-file diff. The IsPassThrough fix is validated by a new cross-framework roundtrip test. The only gaps are cookie-param error message issues in fiber v2 and v3, which are pre-existing issues not introduced by this PR. pkg/codegen/templates/fiber/fiber-middleware.tmpl and pkg/codegen/templates/fiber-v3/fiber-middleware.tmpl cookie required-param error handling.
|
| Filename | Overview |
|---|---|
| pkg/codegen/templates/fiber/fiber-middleware.tmpl | Fixed IsPassThrough header assignment and required-param error for query/header params; cookie required-param error still has wrong "Query argument" message and redundant err assignment. |
| pkg/codegen/templates/fiber-v3/fiber-middleware.tmpl | Fixed IsPassThrough header-param assignment and required-param error handling for query/header params; gated auth-scope SetUserValue behind EnableAuthScopesOnContext. Cookie required-param error still says "Query argument" and uses the old two-step pattern. |
| pkg/codegen/templates/fiber-v3/fiber-receiver.tmpl | New template for fiber-v3 webhook/callback receivers; header IsPassThrough correctly uses a two-step local-variable assignment before writing to params struct. |
| pkg/codegen/templates/strict/strict-http.tmpl | Added nil-guard defaults for RequestErrorHandlerFunc and ResponseErrorHandlerFunc in NewStrictHandlerWithOptions, preventing nil-dereference panics when a zero-value StrictHTTPServerOptions is passed. |
| pkg/codegen/templates/strict/strict-iris.tmpl | Changed handler and response-visitor errors from StatusBadRequest to StatusInternalServerError; improved the unexpected-response-type path to use StopWithError instead of Writef. |
| pkg/codegen/templates/strict/strict-fiber.tmpl | Stopped wrapping handler and visitor errors as fiber 400 errors; errors now propagate as-is so their original status codes are preserved. |
| pkg/codegen/templates/iris/iris-handler.tmpl | Added middleware registration loop so IrisServerOptions.Middlewares are actually applied (previously accepted but silently ignored). |
| pkg/codegen/codegen.go | Added GenerateFiberV3Receiver calls for webhook and callback operations, wiring the new fiber-v3 receiver template into the generation pipeline. |
| internal/test/parameters/roundtrip/param_roundtrip_test.go | Added a cross-framework regression test for IsPassThrough header parameters confirming pass-through values now reach the handler. |
| internal/test/servers/middleware/iris/main_test.go | New regression test verifying that IrisServerOptions.Middlewares are now actually executed. |
| internal/test/go.mod | Added gofiber/fiber/v3 v3.4.0 as a direct dependency; several indirect deps bumped as transitive pull-ins from fiber/v3. |
Reviews (2): Last reviewed commit: "fix: default nil error handlers in NewSt..." | Re-trigger Greptile
fiber v3 was the only server backend without webhook and callback receiver generation. Add a fiber-v3 receiver template (fiber v2's adapted to the v3 `fiber.Ctx` by-value interface signature), the GenerateFiberV3Receiver renderer, and codegen wiring for both webhook and callback operations. Also add internal/test/events/webhooks/fiberv3 for compile coverage, mirroring the other backends; this introduces gofiber/fiber/v3 as a dependency of the test-only internal/test module -- previously no fiber v3 output was compile-tested there at all. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The iris RegisterHandlersWithOptions declared a Middlewares option but never read it, so user-supplied middlewares were silently ignored. Apply them via router.Use() before route registration, matching how fiber treats its equivalent Middlewares option. The loop sits outside the operations guard so middlewares register even for a spec with no operations. Adds a runtime regression test under internal/test/servers/middleware, which fails against the previous template. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
All nine server wrapper templates bound a pass-through (non-JSON content) header param by assigning params.X directly, then unconditionally re-assigned params.X from a local variable that the pass-through branch never set -- so the handler always received the zero value. The JSON and styled branches bind through the local, which is why the trailing assignment exists. Assign the local in the pass-through branch instead, letting the shared trailing assignment (and its optional-pointer handling) apply uniformly to all three branches. The receiver templates already did this correctly; the wrappers never got the same shape. Adds a text/plain content header param to the parameter round-trip suite, which fails on every backend without this fix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The fiber v2 and v3 wrappers built the required-header-missing message
with fmt.Errorf("...: %w", err), but in that branch the header was
simply absent -- err is nil (rendering "%!w(<nil>)" in the response)
or stale from a previously bound parameter, leaking an unrelated error
into the message.
Return the plain message instead, matching the fiber receiver template
and every other backend.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The fiber v2 and v3 wrappers handled a missing required pass-through
or JSON-content query parameter by writing c.Status(400).JSON(err) --
which marshals a bare error to "{}" -- and then also returning the raw
error, so fiber's default error handler ran again on the
already-written response and reported 500 for a client error.
Return fiber.NewError(400, ...) instead, matching every sibling
binding branch and the fiber receiver template.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The fiber v2/v3 and iris strict handlers reported errors returned by the user's handler -- and failures while writing the response -- as HTTP 400, conflating server-side failures with client errors. Every other backend reports these as 500. Iris additionally wrote the "unexpected response type" message without setting any status code, producing an implicit 200. Fiber now returns the raw error into fiber's error chain (matching echo): the default error handler yields 500, custom app error handlers receive the untouched error, and handlers that deliberately return a *fiber.Error keep control of their status. Iris now uses StopWithError(500, ...) for all three failure paths. Adds runtime regression tests for fiber and iris asserting a handler error surfaces as 500; both fail against the previous templates. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The shared strict template for chi, gorilla and stdhttp stored the caller's StrictHTTPServerOptions verbatim, so leaving either error handler nil (e.g. passing a zero-value options struct) caused a nil-function panic on the first request or response error. Fill in the same defaults NewStrictHandler already uses (400 for request errors, 500 for response errors), matching what the gin strict template does. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
fbfec53 to
a0f2c26
Compare
I used AI to survey all of our router templates, since they've drifted independently over the years, and this large batch commit contains several individual fixes as separate commits. I intend to merge them all without squashing.