Support handler-specific middleware for gofiber#2302
Conversation
Greptile SummaryThis PR adds support for handler-specific middleware in the gofiber code generation path, mirroring a capability that already exists for chi/echo. It introduces a new Key changes:
Confidence Score: 5/5This PR is safe to merge — it is a purely additive change and is well-covered by tests. The change is additive: existing callers that don't set HandlerMiddlewares get the same generated code path (an empty slice causes the loop to no-op). The middleware chaining closure correctly captures loop variables (m and next) to avoid the classic Go closure-in-loop issue. The execution order (first element runs outermost) is intuitive and matches chi's ApplyChiMiddlewareFirstToLast behavior. Tests cover registration, middleware interop, and the secured/unsecured endpoint distinction. No files require special attention.
|
| Filename | Overview |
|---|---|
| pkg/codegen/templates/fiber/fiber-middleware.tmpl | Adds HandlerMiddlewareFunc type and wraps each handler in the middleware chain; also fixes security scope key generation with sanitizeGoIdentity. |
| pkg/codegen/templates/fiber/fiber-handler.tmpl | Adds HandlerMiddlewares field to FiberServerOptions and propagates it to ServerInterfaceWrapper. |
| internal/test/issues/issue518/main_test.go | New integration test covering basic registration and auth middleware differentiation based on security scopes; tests both secured and unsecured endpoints. |
| internal/test/issues/issue518/spec.yaml | New OpenAPI spec defining two endpoints: /auth-check (with bearerAuth security scheme) and /test (no auth), used for issue518 tests. |
| internal/test/issues/issue518/config.yaml | Standard oapi-codegen config enabling fiber-server and models generation for the issue518 test package. |
| internal/test/issues/issue518/doc.go | Standard go:generate declaration for the issue518 test package. |
Reviews (1): Last reviewed commit: "chore(fiber): regenerate existing fiber ..." | Re-trigger Greptile
|
Thank you! |
This PR adds support for handler-specific middleware for gofiber, as mentioned in #518. This is useful when different endpoints require different middleware to be added, e.g. for custom auth.