Skip to content

Codegen: add fiber v3 support#2431

Merged
mromaszewicz merged 10 commits into
oapi-codegen:mainfrom
dillonbuchanan-maia-tech:add-fiber-v3
Jul 9, 2026
Merged

Codegen: add fiber v3 support#2431
mromaszewicz merged 10 commits into
oapi-codegen:mainfrom
dillonbuchanan-maia-tech:add-fiber-v3

Conversation

@dillonbuchanan-maia-tech

Copy link
Copy Markdown
Contributor

This continues #1937 (by @kerak19), bringing Fiber v3 support up to date with current main and stable Fiber v3 (v3.3.0). The original PR targeted v3.0.0-beta.4 and an older template base, so the templates no longer matched either current main or stable Fiber v3.

The original commits are preserved; a final commit adapts them.

Fiber v3 API changes since beta.4 (verified against the v3.3.0 source)

  • c.Context() now returns context.Context (not *fasthttp.RequestCtx), so it has no SetUserValue. The security-scopes path was a compile error → c.RequestCtx().SetUserValue(...).
  • ctx.BodyParser was removed (replaced by Bind()) → ctx.Bind().Body().
  • ctx.UserContext() was removed → ctx.Context().
  • GetReqHeaders() returns map[string][]string; the v3 header binding passed a []string where a string was required (compile error).

Template drift fixed

The v3 templates were copied from a beta.4-era v2 base and had since diverged. The v3 non-strict templates and the strict-interface template are regenerated from their current v2 counterparts (only difference: Fiber v3 passes Ctx by value, *fiber.Ctxfiber.Ctx). This also corrects an inverted cookie-presence check, missing Type/Format binding options, a stale BindQueryParameter, missing IsAlias guards, per-handler middleware support, and the SummaryAsComment(prefix) signature.

Codegen wiring

Fiber v3 imports now route through GenerateOptions.RouterImports() (the mechanism introduced on main) rather than the original hardcoded import branch. Added FiberV3Server to RouterImports() and AnyOperationGenerator().

Docs / cmd

  • README: the Fiber v3 row used the v2 fiber-server option → fiber-v3-server; fixed an anchor typo.
  • Added fiber-v3 to the -generate help text.

Verification

  • Root, examples, and internal/test build, test, and lint clean.
  • petstore-expanded/fiberv3 round-trip test passes against Fiber v3.3.0.
  • Strict + security generated servers compile against Fiber v3.3.0.
  • go generate produces zero drift from the committed .gen.go files.

Known limitations (carried over from #1937)

  • Middleware dependency: oapi-codegen/fiber-middleware still has no released v3//v2 module, so the petstore example uses a replace to @kerak19's fork. This should switch to an official github.com/oapi-codegen/fiber-middleware/v2 once published.
  • No automated test for the strict-server / security paths yet (compile-verified only).
  • Strict optional request bodies: v3's Bind().Body() returns a parse error (not io.EOF) on an empty body, so the v2 empty-optional-body tolerance is not ported.
  • No webhook/callback receiver generation for Fiber v3 (parity gap with v2).

kerak19 and others added 6 commits June 29, 2026 16:24
Important change: the GenerateImports now accepts whole configuration, so it can use the information to know which version of package to import.

Currently it's only used for fiber but in the future can be used for any other import with major version increment
The upstream PR targeted fiber v3.0.0-beta.4 and an older oapi-codegen
template base. Bring it up to date so it compiles and works against
fiber v3.3.0 (stable) and current main:

Template fixes (fiber v3 API changes since beta.4):
- middleware/strict: c.Context() now returns context.Context, not
  *fasthttp.RequestCtx; use c.RequestCtx().SetUserValue for scopes.
- strict: ctx.BodyParser was removed; use ctx.Bind().Body. ctx.UserContext
  was removed; use ctx.Context().
- regenerate the v3 non-strict templates (handler/interface/middleware)
  and the strict interface template from their current v2 counterparts,
  substituting *fiber.Ctx -> fiber.Ctx (v3 passes Ctx by value). This
  pulls in fixes the v3 copies were missing: GetReqHeaders() returns
  map[string][]string (header binding was passing []string where a string
  was wanted, a compile error), inverted cookie-presence check, missing
  Type/Format binding options, BindQueryParameterWithOptions, IsAlias
  guards, per-handler middleware, SummaryAsComment(prefix) signature.

Codegen wiring:
- imports.tmpl/codegen.go: drop the PR's hardcoded FiberV3 import branch;
  route fiber/v3 through the new GenerateOptions.RouterImports() mechanism
  on main. Add FiberV3Server to RouterImports() and AnyOperationGenerator().

Examples / deps:
- examples/go.mod: require gofiber/fiber/v3 v3.3.0 and the (still
  unreleased upstream) fiber-middleware/v2, via a replace to the author's
  v3 fork until oapi-codegen/fiber-middleware ships v2.
- regenerate example .gen.go; use api.GetSpec() (GetSwagger is deprecated).

Docs/cmd:
- README: the Fiber v3 row used the v2 `fiber-server` option; fix to
  `fiber-v3-server`. Fix anchor typo.
- add fiber-v3 to the -generate help text.

Verified: root + examples + internal/test build, test, and lint clean;
petstore-expanded/fiberv3 round-trip test passes against fiber v3.3.0;
strict + security generated servers compile against fiber v3.3.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dillonbuchanan-maia-tech
dillonbuchanan-maia-tech requested a review from a team as a code owner June 29, 2026 20:52
@socket-security

socket-security Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​gofiber/​fiber/​v3@​v3.4.074100100100100
Addedgithub.com/​oapi-codegen/​fiber-v3-middleware@​v0.1.0100100100100100

View full report

@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds Fiber v3 (github.com/gofiber/fiber/v3) as a new server backend for oapi-codegen, rebased onto current main and targeting the stable v3.3.0 release. It covers full codegen wiring, non-strict and strict templates, a petstore roundtrip example, documentation, and the necessary JSON schema update.

  • Core wiring: FiberV3Server is added to GenerateOptions, RouterImports(), AnyOperationGenerator(), Validate(), and the generation pipeline in codegen.go \u2014 all following the established pattern for other backends.
  • Template correctness: The v3 templates fix known breaking changes since beta.4 (c.RequestCtx().SetUserValue for security scopes, Bind().Body() replacing BodyParser, GetReqHeaders() returning []string, fiber.Ctx by value). Strict templates are included and compile-verified against v3.3.0.
  • Known gap: No fiber-v3 directory exists under internal/test/servers/ \u2014 the integration-test module that provides parity coverage for every other backend. The examples/go.mod replace directive pointing to a personal fork is an acknowledged temporary limitation documented in the PR description.

Confidence Score: 5/5

Safe to merge — the change is additive (new opt-in backend, no existing API altered) and the generated output compiles cleanly against Fiber v3.3.0.

The codegen wiring, templates, and generated files are all consistent with how other backends are implemented. No existing generated API surface is changed, and the new backend is purely opt-in via fiber-v3-server: true. The only notable gap is the absence of internal/test/servers/fiber-v3/ integration tests, which every other backend has, but that does not affect correctness of the merged output.

internal/test/servers/ — a fiber-v3 router test directory analogous to internal/test/servers/fiber/ would close the parity gap with other backends.

Important Files Changed

Filename Overview
pkg/codegen/configuration.go Adds FiberV3Server to GenerateOptions, RouterImports switch, AnyOperationGenerator, and Validate nServers counter — all correctly wired following existing patterns.
configuration-schema.json Adds the required fiber-v3-server boolean entry; schema stays in sync with the configuration.go struct change.
pkg/codegen/codegen.go Adds FiberV3Server generation call and write-string block following the same pattern as every other backend.
pkg/codegen/operations.go Adds GenerateFiberV3Server function and wires fiber-v3 strict templates into GenerateStrictServer, mirroring the fiber-v2 approach.
pkg/codegen/templates/fiber-v3/fiber-middleware.tmpl Core parameter-binding template with correct v3 API fixes. Per-handler middleware chaining uses safe closure capture.
pkg/codegen/templates/strict/strict-fiber-v3.tmpl Strict handler wrapper; uses ctx.Context() correctly for v3 and Bind().Body() for bodies. All errors mapped to 400, consistent with v2 template.
pkg/codegen/templates/strict/strict-fiber-v3-interface.tmpl Strict interface and response-visitor template; Visit*Response methods use fiber v3 API correctly.
examples/petstore-expanded/fiberv3/api/petstore-server.gen.go Generated file matches expected template output with correct fiber v3 patterns.
examples/go.mod Adds fiber/v3 and the kerak19 fork replace directive (documented known limitation).
docs/fiber-v3-server.md New documentation page correctly documents the fiber-v3-server generate option and usage.

Reviews (3): Last reviewed commit: "fiber-v3: restore GenerateImports signat..." | Re-trigger Greptile

Comment thread pkg/codegen/templates/fiber-v3/fiber-middleware.tmpl
Comment thread examples/go.mod Outdated
- middleware: fix cookie IsPassThrough branch emitting `}&cookie` (a
  compile error for optional pass-through cookie params). Bug was carried
  over verbatim from the v2 template; corrected here. Verified by
  generating a server with an optional text/plain cookie param.
- configuration: fix copy-paste comment on FiberV3Server field.
- strict: use `any` instead of `interface{}` in StrictHandlerFunc to match
  the v2 strict-fiber template.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dillonbuchanan-maia-tech

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in 7adc99f:

  1. Cookie IsPassThrough }&cookie typo (P1) — fixed. This bug was carried over verbatim from the v2 fiber-middleware.tmpl, so the same latent issue exists there for optional pass-through cookie params. Verified the fix by generating a server from a spec with an optional text/plain cookie parameter: it now emits params.Session = &cookie and compiles (previously a compile error).
  2. FiberV3Server copy-paste comment — fixed.
  3. interface{} vs any in StrictHandlerFunc — aligned to any to match the v2 strict-fiber template.
  4. replace to a personal fiber-middleware fork — acknowledged; left in place as the documented temporary workaround until an official github.com/oapi-codegen/fiber-middleware/v2 is published. It's called out in both the go.mod comment and the PR description.

Root + examples + internal/test still build, test, and lint clean, and go generate shows no drift.

…lidation

Two simplifications to keep the fiber v3 support purely additive:

- Restore the exported `GenerateImports` signature
  (`packageName string, versionOverride *string`) instead of changing it
  to take a `Configuration`. The fiber v3 import is emitted via
  `GenerateOptions.RouterImports()`, which `GenerateImports` already
  reads from the global state, so the signature change bought nothing
  and would have broken downstream consumers of `pkg/codegen` that call
  the function directly.

- Count `FiberV3Server` in `Configuration.Validate`'s single-server
  check, which otherwise allowed `fiber-v3-server` to be combined with
  another server type in one generation run.
@mromaszewicz mromaszewicz added enhancement New feature or request notable changes Used for release notes to highlight these more highly labels Jul 9, 2026
Now that github.com/oapi-codegen/fiber-v3-middleware v0.1.0 is
published, drop the temporary `replace` directive that pointed the
fiber v3 petstore example at a fork's `fiber-middleware/v2` branch, and
import the released module instead.

Aligns `github.com/gofiber/fiber/v3` to v3.4.0 to match the middleware
release.
@mromaszewicz

Copy link
Copy Markdown
Member

I've fixed up the PR to be consistent with our other routers, and also released a new fiber V3 middleware, so we don't need to use a replace directive to a personal fork of fiber middleware.

@mromaszewicz
mromaszewicz merged commit 596935e into oapi-codegen:main Jul 9, 2026
15 checks passed
@jamietanna jamietanna changed the title Codegen: add fiber v3 support (rebased on main, fiber v3 stable) Codegen: add fiber v3 support Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request notable changes Used for release notes to highlight these more highly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants