Skip to content

Commit 717f462

Browse files
jinuthankachanDanDagaditamromaszewiczclaude
authored
feat: Support echo/v5 (#2188)
* feat: server code generation for echo/v5 * feat/echov5-codegen (#6) * server code generation for echo/v5 * does not include: - strict-server for echo/v5 - middlewares for echo/v5 * fix: rename PathParam to Param for echo/v5 * fix: missing parts for strict server (#9) * fix: add the missing strict server generation * Clean up router imports Instead of hardcoding each router's framework and strict middleware imports directly in imports.tmpl with per-router conditional blocks, compute them in Go code via GenerateOptions.RouterImports() and pass them to the template as RouterImports. The template now uses a single range loop over .RouterImports, making it straightforward to add new routers without touching the template. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add petstore-expanded/echo-v5 example Echo v5 version of the petstore-expanded example, in its own Go module (go 1.25.0) to avoid bumping the Go version of the shared examples module. Key differences from the echo (v4) example: - *echo.Context (pointer) instead of echo.Context (interface) - echo.NewHTTPError(code, message) takes exactly two args - No HTTPError.Internal field - EchoRouter returns echo.RouteInfo instead of *echo.Route - log.Fatal(e.Start(...)) instead of e.Logger.Fatal(...) Includes an inline OpenAPI request validation middleware (middleware/) adapted from echo-middleware for echo v5, since no published echo-v5 middleware package exists yet. Models and server stubs are placeholders until the codegen circular dependency for go:generate in isolated modules is resolved. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: skip echo-v5 example on Go < 1.25 The echo-v5 example requires Go 1.25+ (for echo/v5). When CI runs with GOTOOLCHAIN=local on Go 1.24, the module refuses to build. Add a Go version guard to the Makefile so all targets skip gracefully with an informational message on older Go versions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: DanDagadita <dandagadita@gmail.com> Co-authored-by: Marcin Romaszewicz <marcinr@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f459fd7 commit 717f462

22 files changed

Lines changed: 1509 additions & 20 deletions

‎cmd/oapi-codegen/oapi-codegen.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ func generationTargets(cfg *codegen.Configuration, targets []string) error {
512512
opts.FiberServer = true
513513
case "server", "echo-server", "echo":
514514
opts.EchoServer = true
515+
case "echo5", "echo5-server":
516+
opts.Echo5Server = true
515517
case "gin", "gin-server":
516518
opts.GinServer = true
517519
case "gorilla", "gorilla-server":

‎configuration-schema.json‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
"type": "boolean",
3030
"description": "EchoServer specifies whether to generate echo server boilerplate"
3131
},
32+
"echo5-server": {
33+
"type": "boolean",
34+
"description": "Echo5Server specifies whether to generate echo v5 server boilerplate"
35+
},
3236
"gin-server": {
3337
"type": "boolean",
3438
"description": "GinServer specifies whether to generate gin server boilerplate"
@@ -197,9 +201,7 @@
197201
"description": "DisableTypeAliasesForType allows defining which OpenAPI `type`s will explicitly not use type aliases",
198202
"items": {
199203
"type": "string",
200-
"enum": [
201-
"array"
202-
]
204+
"enum": ["array"]
203205
}
204206
},
205207
"name-normalizer": {
@@ -226,9 +228,7 @@
226228
"default": true
227229
}
228230
},
229-
"required": [
230-
"path"
231-
]
231+
"required": ["path"]
232232
},
233233
"yaml-tags": {
234234
"type": "boolean",
@@ -299,9 +299,7 @@
299299
"type": "string"
300300
}
301301
},
302-
"required": [
303-
"package"
304-
]
302+
"required": ["package"]
305303
},
306304
"description": "AdditionalImports defines any additional Go imports to add to the generated code"
307305
},
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This module requires Go 1.25+ (for echo/v5). Skip gracefully on older versions.
2+
GO_VERSION := $(shell go version | sed 's/.*go\([0-9]*\)\.\([0-9]*\).*/\1\2/')
3+
GO_125_OR_LATER := $(shell [ "$(GO_VERSION)" -ge 125 ] 2>/dev/null && echo yes || echo no)
4+
5+
ifeq ($(GO_125_OR_LATER),yes)
6+
7+
lint:
8+
$(GOBIN)/golangci-lint run ./...
9+
10+
lint-ci:
11+
$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m
12+
13+
generate:
14+
go generate ./...
15+
16+
test:
17+
go test -cover ./...
18+
19+
tidy:
20+
go mod tidy
21+
22+
tidy-ci:
23+
tidied -verbose
24+
25+
else
26+
27+
lint generate test tidy lint-ci tidy-ci:
28+
@echo "Skipping echo-v5 example: requires Go 1.25+ (found $(shell go version))"
29+
30+
endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yaml-language-server: $schema=../../../../configuration-schema.json
2+
package: models
3+
generate:
4+
models: true
5+
output: models/models.gen.go

‎examples/petstore-expanded/echo-v5/api/models/models.gen.go‎

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/petstore-expanded/echo-v5/api/petstore-server.gen.go‎

Lines changed: 247 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)