Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit b925051

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents e207ce9 + a7de76c commit b925051

File tree

142 files changed

+8306
-633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+8306
-633
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ permissions:
77
contents: read
88
jobs:
99
build:
10-
uses: oapi-codegen/actions/.github/workflows/ci.yml@b9f2c274c1c631e648931dbbcc1942c2b2027837 # v0.4.0
10+
uses: oapi-codegen/actions/.github/workflows/ci.yml@75566d848d25021f137594c947f26171094fb511 # v0.5.0
11+
with:
12+
lint_versions: '["1.25"]'
1113

1214
build-binaries:
1315
runs-on: ubuntu-latest

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ Server
431431
<code>generate</code> flag to enable code generation
432432
</th>
433433
<th>
434+
Required Go Version
435+
</th>
436+
<th>
434437
Example usage
435438
</th>
436439
</tr>
@@ -445,6 +448,9 @@ Example usage
445448
<code>chi-server</code>
446449
</td>
447450
<td>
451+
1.22+
452+
</td>
453+
<td>
448454

449455

450456
For a Chi server, you will want a configuration file such as:
@@ -473,6 +479,9 @@ To implement this, check out [the Chi docs](#impl-chi).
473479
<code>echo-server</code>
474480
</td>
475481
<td>
482+
1.22+
483+
</td>
484+
<td>
476485
477486
For an Echo server, you will want a configuration file such as:
478487
@@ -499,7 +508,9 @@ To implement this, check out [the Echo docs](#impl-echo).
499508
<td>
500509
<code>fiber-server</code>
501510
</td>
502-
511+
<td>
512+
1.24+
513+
</td>
503514
<td>
504515
505516
For a Fiber server, you will want a configuration file such as:
@@ -529,6 +540,9 @@ To implement this, check out [the Fiber docs](#impl-fiber).
529540
<code>gin-server</code>
530541
</td>
531542
<td>
543+
1.22+
544+
</td>
545+
<td>
532546
533547
For a Gin server, you will want a configuration file such as:
534548
@@ -556,7 +570,9 @@ To implement this, check out [the Gin docs](#impl-gin).
556570
<td>
557571
<code>gorilla-server</code>
558572
</td>
559-
573+
<td>
574+
1.22+
575+
</td>
560576
<td>
561577
562578
For a gorilla/mux server, you will want a configuration file such as:
@@ -584,7 +600,9 @@ To implement this, check out [the gorilla/mux docs](#impl-gorillamux).
584600
<td>
585601
<code>iris-server</code>
586602
</td>
587-
603+
<td>
604+
1.22+
605+
</td>
588606
<td>
589607
590608
For a Iris server, you will want a configuration file such as:
@@ -612,7 +630,9 @@ To implement this, check out [the Iris docs](#impl-iris).
612630
<td>
613631
<code>std-http-server</code>
614632
</td>
615-
633+
<td>
634+
1.22+
635+
</td>
616636
<td>
617637

618638
To use purely `net/http` (for Go 1.22+), you will want a configuration file such as:

cmd/oapi-codegen/oapi-codegen.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"github.com/oapi-codegen/oapi-codegen/v2/pkg/util"
3030
)
3131

32-
func errExit(format string, args ...interface{}) {
32+
func errExit(format string, args ...any) {
3333
if !strings.HasSuffix(format, "\n") {
3434
format = format + "\n"
3535
}
@@ -272,12 +272,13 @@ func main() {
272272
}
273273

274274
if warnings := opts.Generate.Warnings(); len(warnings) > 0 {
275-
out := "WARNING: A number of warning(s) were returned when validating the GenerateOptions:"
275+
var out strings.Builder
276+
out.WriteString("WARNING: A number of warning(s) were returned when validating the GenerateOptions:")
276277
for k, v := range warnings {
277-
out += "\n- " + k + ": " + v
278+
out.WriteString("\n- " + k + ": " + v)
278279
}
279280

280-
_, _ = fmt.Fprint(os.Stderr, out)
281+
_, _ = fmt.Fprint(os.Stderr, out.String())
281282
}
282283

283284
// If the user asked to output configuration, output it to stdout and exit

configuration-schema.json

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,25 @@
257257
"type": "boolean",
258258
"description": "When set to true, automatically renames types that collide across different OpenAPI component sections (schemas, parameters, requestBodies, responses, headers) by appending a suffix based on the component section (e.g., 'Parameter', 'Response', 'RequestBody'). Without this, the codegen will error on duplicate type names, requiring manual resolution via x-go-name.",
259259
"default": false
260+
},
261+
"type-mapping": {
262+
"type": "object",
263+
"additionalProperties": false,
264+
"description": "TypeMapping allows customizing OpenAPI type/format to Go type mappings. User-specified mappings are merged on top of the defaults, so you only need to specify the types you want to override.",
265+
"properties": {
266+
"integer": {
267+
"$ref": "#/$defs/format-mapping"
268+
},
269+
"number": {
270+
"$ref": "#/$defs/format-mapping"
271+
},
272+
"boolean": {
273+
"$ref": "#/$defs/format-mapping"
274+
},
275+
"string": {
276+
"$ref": "#/$defs/format-mapping"
277+
}
278+
}
260279
}
261280
}
262281
},
@@ -294,5 +313,43 @@
294313
"required": [
295314
"package",
296315
"output"
297-
]
316+
],
317+
"$defs": {
318+
"simple-type-spec": {
319+
"type": "object",
320+
"additionalProperties": false,
321+
"description": "Specifies a Go type and optional import path",
322+
"properties": {
323+
"type": {
324+
"type": "string",
325+
"description": "The Go type to use (e.g. \"int64\", \"time.Time\", \"github.com/shopspring/decimal.Decimal\")"
326+
},
327+
"import": {
328+
"type": "string",
329+
"description": "The Go import path required for this type (e.g. \"time\", \"encoding/json\")"
330+
}
331+
},
332+
"required": [
333+
"type"
334+
]
335+
},
336+
"format-mapping": {
337+
"type": "object",
338+
"additionalProperties": false,
339+
"description": "Maps an OpenAPI type's formats to Go types",
340+
"properties": {
341+
"default": {
342+
"$ref": "#/$defs/simple-type-spec",
343+
"description": "The default Go type when no format is specified or the format is unrecognized"
344+
},
345+
"formats": {
346+
"type": "object",
347+
"description": "Format-specific Go type overrides (e.g. \"int32\": {\"type\": \"int32\"}, \"double\": {\"type\": \"float64\"})",
348+
"additionalProperties": {
349+
"$ref": "#/$defs/simple-type-spec"
350+
}
351+
}
352+
}
353+
}
354+
}
298355
}

examples/Makefile

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
1-
SHELL:=/bin/bash
2-
3-
YELLOW := \e[0;33m
4-
RESET := \e[0;0m
5-
6-
GOVER := $(shell go env GOVERSION)
7-
GOMINOR := $(shell bash -c "cut -f1 -d' ' <<< \"$(GOVER)\" | cut -f2 -d.")
8-
9-
define execute-if-go-124
10-
@{ \
11-
if [[ 24 -le $(GOMINOR) ]]; then \
12-
$1; \
13-
else \
14-
echo -e "$(YELLOW)Skipping task as you're running Go v1.$(GOMINOR).x which is < Go 1.24, which this module requires$(RESET)"; \
15-
fi \
16-
}
17-
endef
18-
191
lint:
20-
$(call execute-if-go-124,$(GOBIN)/golangci-lint run ./...)
2+
$(GOBIN)/golangci-lint run ./...
213

224
lint-ci:
23-
24-
$(call execute-if-go-124,$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m)
5+
$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m
256

267
generate:
27-
$(call execute-if-go-124,go generate ./...)
8+
go generate ./...
289

2910
test:
30-
$(call execute-if-go-124,go test -cover ./...)
11+
go test -cover ./...
3112

3213
tidy:
33-
$(call execute-if-go-124,go mod tidy)
14+
go mod tidy
3415

3516
tidy-ci:
36-
$(call execute-if-go-124,tidied -verbose)
17+
tidied -verbose

examples/generate/serverurls/gen.go

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/go.mod

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
module github.com/oapi-codegen/oapi-codegen/v2/examples
22

3-
go 1.24.0
3+
go 1.22.5
44

55
replace github.com/oapi-codegen/oapi-codegen/v2 => ../
66

77
require (
88
github.com/getkin/kin-openapi v0.133.0
99
github.com/gin-gonic/gin v1.10.0
1010
github.com/go-chi/chi/v5 v5.0.10
11-
github.com/gofiber/fiber/v2 v2.52.11
1211
github.com/google/uuid v1.6.0
1312
github.com/gorilla/mux v1.8.1
1413
github.com/kataras/iris/v12 v12.2.6-0.20230908161203-24ba4e8933b9
1514
github.com/labstack/echo/v4 v4.12.0
1615
github.com/lestrrat-go/jwx v1.2.26
1716
github.com/oapi-codegen/echo-middleware v1.0.2
18-
github.com/oapi-codegen/fiber-middleware v1.0.2
1917
github.com/oapi-codegen/gin-middleware v1.0.2
2018
github.com/oapi-codegen/iris-middleware v1.0.5
2119
github.com/oapi-codegen/nethttp-middleware v1.0.2
@@ -32,12 +30,11 @@ require (
3230
github.com/CloudyKit/jet/v6 v6.2.0 // indirect
3331
github.com/Joker/jade v1.1.3 // indirect
3432
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect
35-
github.com/andybalholm/brotli v1.2.0 // indirect
33+
github.com/andybalholm/brotli v1.1.0 // indirect
3634
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
3735
github.com/aymerick/douceur v0.2.0 // indirect
3836
github.com/bytedance/sonic v1.11.6 // indirect
3937
github.com/bytedance/sonic/loader v0.1.1 // indirect
40-
github.com/clipperhouse/uax29/v2 v2.6.0 // indirect
4138
github.com/cloudwego/base64x v0.1.4 // indirect
4239
github.com/cloudwego/iasm v0.2.0 // indirect
4340
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -65,7 +62,7 @@ require (
6562
github.com/kataras/pio v0.0.12 // indirect
6663
github.com/kataras/sitemap v0.0.6 // indirect
6764
github.com/kataras/tunnel v0.0.4 // indirect
68-
github.com/klauspost/compress v1.18.4 // indirect
65+
github.com/klauspost/compress v1.17.9 // indirect
6966
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
7067
github.com/labstack/gommon v0.4.2 // indirect
7168
github.com/leodido/go-urn v1.4.0 // indirect
@@ -76,9 +73,8 @@ require (
7673
github.com/lestrrat-go/option v1.0.1 // indirect
7774
github.com/mailgun/raymond/v2 v2.0.48 // indirect
7875
github.com/mailru/easyjson v0.7.7 // indirect
79-
github.com/mattn/go-colorable v0.1.14 // indirect
76+
github.com/mattn/go-colorable v0.1.13 // indirect
8077
github.com/mattn/go-isatty v0.0.20 // indirect
81-
github.com/mattn/go-runewidth v0.0.19 // indirect
8278
github.com/microcosm-cc/bluemonday v1.0.25 // indirect
8379
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
8480
github.com/modern-go/reflect2 v1.0.2 // indirect
@@ -99,22 +95,21 @@ require (
9995
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
10096
github.com/ugorji/go/codec v1.2.12 // indirect
10197
github.com/valyala/bytebufferpool v1.0.0 // indirect
102-
github.com/valyala/fasthttp v1.69.0 // indirect
10398
github.com/valyala/fasttemplate v1.2.2 // indirect
10499
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
105100
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
106101
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
107102
github.com/woodsbury/decimal128 v1.3.0 // indirect
108103
github.com/yosssi/ace v0.0.5 // indirect
109104
golang.org/x/arch v0.8.0 // indirect
110-
golang.org/x/crypto v0.46.0 // indirect
111-
golang.org/x/mod v0.30.0 // indirect
112-
golang.org/x/net v0.48.0 // indirect
113-
golang.org/x/sync v0.19.0 // indirect
114-
golang.org/x/sys v0.41.0 // indirect
115-
golang.org/x/text v0.32.0 // indirect
105+
golang.org/x/crypto v0.33.0 // indirect
106+
golang.org/x/mod v0.23.0 // indirect
107+
golang.org/x/net v0.35.0 // indirect
108+
golang.org/x/sync v0.11.0 // indirect
109+
golang.org/x/sys v0.30.0 // indirect
110+
golang.org/x/text v0.22.0 // indirect
116111
golang.org/x/time v0.5.0 // indirect
117-
golang.org/x/tools v0.39.0 // indirect
112+
golang.org/x/tools v0.30.0 // indirect
118113
google.golang.org/protobuf v1.34.1 // indirect
119114
gopkg.in/ini.v1 v1.67.0 // indirect
120115
gopkg.in/yaml.v2 v2.4.0 // indirect

0 commit comments

Comments
 (0)