Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ older version of Go, we don't promise that it'll work.
| [Echo](https://github.com/labstack/echo) | `echo-server` | 1.24+ | [Echo documentation](docs/echo-server.md) |
| [Echo v5](https://github.com/labstack/echo) | `echo5-server` | 1.25+ | [Echo v5 documentation](docs/echo5-server.md) |
| [Fiber](https://github.com/gofiber/fiber) | `fiber-server` | 1.24+ | [Fiber documentation](docs/fiber-server.md) |
| [Fiber v3](https://github.com/gofiber/fiber) | `fiber-v3-server` | 1.25+ | [Fiber v3 documentation](docs/fiber-v3-server.md) |
| [Gin](https://github.com/gin-gonic/gin) | `gin-server` | 1.25+ | [Gin documentation](docs/gin-server.md) |
| [gorilla/mux](https://github.com/gorilla/mux) | `gorilla-server` | 1.24+ | [gorilla/mux documentation](docs/gorilla-server.md) |
| [Iris](https://github.com/kataras/iris) | `iris-server` | 1.24+ | [Iris documentation](docs/iris-server.md) |
Expand Down
4 changes: 3 additions & 1 deletion cmd/oapi-codegen/oapi-codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {
// All flags below are deprecated, and will be removed in a future release. Please do not
// update their behavior.
flag.StringVar(&flagGenerate, "generate", "types,client,server,spec",
`Comma-separated list of code to generate; valid options: "types", "client", "chi-server", "server", "gin", "gorilla", "spec", "skip-fmt", "skip-prune", "fiber", "iris", "std-http".`)
`Comma-separated list of code to generate; valid options: "types", "client", "chi-server", "server", "gin", "gorilla", "spec", "skip-fmt", "skip-prune", "fiber", "fiber-v3", "iris", "std-http".`)
flag.StringVar(&flagIncludeTags, "include-tags", "", "Only include operations with the given tags. Comma-separated list of tags.")
flag.StringVar(&flagExcludeTags, "exclude-tags", "", "Exclude operations that are tagged with the given tags. Comma-separated list of tags.")
flag.StringVar(&flagIncludeOperationIDs, "include-operation-ids", "", "Only include operations with the given operation-ids. Comma-separated list of operation-ids.")
Expand Down Expand Up @@ -527,6 +527,8 @@ func generationTargets(cfg *codegen.Configuration, targets []string) error {
opts.ChiServer = true
case "fiber-server", "fiber":
opts.FiberServer = true
case "fiber-v3-server", "fiber-v3":
opts.FiberV3Server = true
case "server", "echo-server", "echo":
opts.EchoServer = true
case "echo5", "echo5-server":
Expand Down
4 changes: 4 additions & 0 deletions configuration-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"type": "boolean",
"description": "FiberServer specifies whether to generate fiber server boilerplate"
},
"fiber-v3-server": {
"type": "boolean",
"description": "FiberV3Server specifies whether to generate fiber-v3 server boilerplate"
},
"echo-server": {
"type": "boolean",
"description": "EchoServer specifies whether to generate echo server boilerplate"
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ generate:
echo-server: false
echo5-server: false # requires Go 1.25+
fiber-server: false
fiber-v3-server: false # requires Go 1.25+
gin-server: false
gorilla-server: false
iris-server: false
Expand Down
135 changes: 135 additions & 0 deletions docs/fiber-v3-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Fiber v3 Server

> [!NOTE]
> Fiber v3 requires Go 1.25+.

For a Fiber v3 server, you will want a configuration file such as:

```yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/oapi-codegen/oapi-codegen/v2.7.2/configuration-schema.json
package: api
generate:
fiber-v3-server: true
models: true
output: gen.go
```

## Generated code

For instance, let's take this straightforward specification:

```yaml
openapi: "3.0.0"
info:
version: 1.0.0
title: Minimal ping API server
paths:
/ping:
get:
responses:
'200':
description: pet response
content:
application/json:
schema:
$ref: '#/components/schemas/Pong'
components:
schemas:
# base types
Pong:
type: object
required:
- ping
properties:
ping:
type: string
example: pong
```

This then generates code such as:

```go
// Pong defines model for Pong.
type Pong struct {
Ping string `json:"ping"`
}

// ServerInterface represents all server handlers.
type ServerInterface interface {

// (GET /ping)
GetPing(c fiber.Ctx) error
}

// MiddlewareFunc is a middleware for the Fiber server.
type MiddlewareFunc fiber.Handler

// FiberServerOptions provides options for the Fiber server.
type FiberServerOptions struct {
BaseURL string
Middlewares []MiddlewareFunc
}

// RegisterHandlers creates http.Handler with routing matching OpenAPI spec.
func RegisterHandlers(router fiber.Router, si ServerInterface) {
RegisterHandlersWithOptions(router, si, FiberServerOptions{})
}
```

Note that unlike Fiber v2, handlers take `fiber.Ctx` (an interface) rather than `*fiber.Ctx`.

To implement this HTTP server, we need to write the following code in our [`api/impl.go`](../examples/minimal-server/fiberv3/api/impl.go):

```go
import (
"net/http"

"github.com/gofiber/fiber/v3"
)

// ensure that we've conformed to the `ServerInterface` with a compile-time check
var _ ServerInterface = (*Server)(nil)

type Server struct{}

func NewServer() Server {
return Server{}
}

// (GET /ping)
func (Server) GetPing(ctx fiber.Ctx) error {
resp := Pong{
Ping: "pong",
}

return ctx.
Status(http.StatusOK).
JSON(resp)
}
```

Now we've got our implementation, we can then write the following code to wire it up and get a running server:

```go
import (
"log"

"github.com/gofiber/fiber/v3"
"github.com/oapi-codegen/oapi-codegen/v2/examples/minimal-server/fiberv3/api"
)

func main() {
// create a type that satisfies the `api.ServerInterface`, which contains an implementation of every operation from the generated code
server := api.NewServer()

app := fiber.New()

api.RegisterHandlers(app, server)

// And we serve HTTP until the world ends.
log.Fatal(app.Listen("0.0.0.0:8080"))
}
```

> [!NOTE]
> This doesn't include [validation of incoming requests](../README.md#requestresponse-validation-middleware).
20 changes: 13 additions & 7 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/gin-gonic/gin v1.12.0
github.com/go-chi/chi/v5 v5.2.5
github.com/gofiber/fiber/v2 v2.52.13
github.com/gofiber/fiber/v3 v3.4.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/kataras/iris/v12 v12.2.11
Expand All @@ -18,6 +19,7 @@ require (
github.com/oapi-codegen/echo-middleware v1.0.2
github.com/oapi-codegen/echo-v5-middleware v0.1.0
github.com/oapi-codegen/fiber-middleware v1.0.2
github.com/oapi-codegen/fiber-v3-middleware v0.1.0
github.com/oapi-codegen/gin-middleware v1.0.2
github.com/oapi-codegen/iris-middleware v1.0.5
github.com/oapi-codegen/nethttp-middleware v1.1.2
Expand All @@ -33,7 +35,7 @@ require (
github.com/CloudyKit/jet/v6 v6.3.2 // indirect
github.com/Joker/jade v1.1.3 // indirect
github.com/Shopify/goreferrer v0.0.0-20250617153402-88c1d9a79b05 // indirect
github.com/andybalholm/brotli v1.2.1 // indirect
github.com/andybalholm/brotli v1.2.2 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/bytedance/gopkg v0.1.4 // indirect
Expand All @@ -54,6 +56,8 @@ require (
github.com/go-playground/validator/v10 v10.30.2 // indirect
github.com/goccy/go-json v0.10.6 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/gofiber/schema v1.8.1 // indirect
github.com/gofiber/utils/v2 v2.1.1 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df // indirect
github.com/gorilla/css v1.0.1 // indirect
Expand All @@ -65,7 +69,7 @@ require (
github.com/kataras/pio v0.0.13 // indirect
github.com/kataras/sitemap v0.0.6 // indirect
github.com/kataras/tunnel v0.0.4 // indirect
github.com/klauspost/compress v1.18.6 // indirect
github.com/klauspost/compress v1.19.0 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/labstack/gommon v0.5.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
Expand All @@ -77,7 +81,7 @@ require (
github.com/lestrrat-go/option/v2 v2.0.0 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mailru/easyjson v0.9.2 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-colorable v0.1.15 // indirect
github.com/mattn/go-isatty v0.0.22 // indirect
github.com/mattn/go-runewidth v0.0.23 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
Expand All @@ -86,6 +90,7 @@ require (
github.com/oasdiff/yaml v0.1.1 // indirect
github.com/oasdiff/yaml3 v0.0.14 // indirect
github.com/pelletier/go-toml/v2 v2.3.0 // indirect
github.com/philhofer/fwd v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.59.0 // indirect
Expand All @@ -98,10 +103,11 @@ require (
github.com/speakeasy-api/openapi v1.23.1 // indirect
github.com/tdewolff/minify/v2 v2.24.13 // indirect
github.com/tdewolff/parse/v2 v2.8.12 // indirect
github.com/tinylib/msgp v1.6.4 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.70.0 // indirect
github.com/valyala/fasthttp v1.72.0 // indirect
github.com/valyala/fastjson v1.6.10 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
Expand All @@ -111,12 +117,12 @@ require (
go.mongodb.org/mongo-driver/v2 v2.6.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.26.0 // indirect
golang.org/x/crypto v0.53.0 // indirect
golang.org/x/crypto v0.54.0 // indirect
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f // indirect
golang.org/x/mod v0.37.0 // indirect
golang.org/x/net v0.56.0 // indirect
golang.org/x/net v0.57.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.40.0 // indirect
golang.org/x/time v0.15.0 // indirect
golang.org/x/tools v0.47.0 // indirect
Expand Down
Loading