Skip to content

feat: support OpenAPI 3.2 QUERY and additionalOperations - #2645

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:feat/issue-2436
Oct 31, 2026
Merged

mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:feat/issue-2436

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Closes #2436

What

OpenAPI 3.2 adds the fixed query operation (HTTP QUERY) and an additionalOperations map of arbitrary HTTP methods to the Path Item. kin-openapi v0.152.0 (already our dependency) surfaces both through PathItem.Operations(), so gathering, pruning, filtering, models and the client already handled them. Route registration did not: every router's per-method shortcut (router.Get, router.GET, ...) has no equivalent for these methods.

paths:
  /items:
    query:
      operationId: queryItems
    additionalOperations:
      PURGE:
        operationId: purgeItem

Generated code

Non-standard methods now register through each router's string-method API:

Router Registration
chi r.MethodFunc("QUERY", ...)
echo v4 / v5 router.Add("QUERY", ...); EchoRouter gains Add only when the spec uses a custom method
gin router.Handle("QUERY", ...)
fiber v2 / v3 router.Add("QUERY", ...) / router.Add([]string{"QUERY"}, ...)
iris router.Handle("QUERY", ...)
net/http, gorilla/mux, client unchanged, already string-based

gin's CONNECT and TRACE also go through Handle now. gin has no shortcut for either, so the previous output did not compile.

Application-side setup (notable)

chi (chi.RegisterMethod) and fiber (Config.RequestMethods) only accept methods they have been told about. The generated code deliberately does not do that setup: it is process-wide state and one process commonly hosts several generated packages. The README section and docs/{chi,fiber,fiber-v3,iris}-server.md describe the one-time step in main(). iris routes custom methods without setup; iris.RegisterMethods is documented as optional for Any() coverage.

Compatibility

Specs that use only standard methods produce byte-identical output; a full make generate changes no pre-existing generated file. The only shape change for affected specs is the Add method on echo's EchoRouter interface, which *echo.Echo and *echo.Group already satisfy.

Testing

New fixture internal/test/servers/routers/methods/ generates a 3.2 spec (GET, QUERY with body, PURGE with path + query params) for all nine server targets plus the client. The test sends real QUERY and PURGE requests through each router and checks parameter binding, and asserts that chi and fiber panic without the documented setup.

make tidy && make test && make generate && make lint all clean.

🤖 Generated with Claude Code

@mromaszewicz mromaszewicz added enhancement New feature or request notable changes Used for release notes to highlight these more highly labels Oct 31, 2026
@mromaszewicz
mromaszewicz requested a review from a team as a code owner October 31, 2026 20:11
@mromaszewicz mromaszewicz added enhancement New feature or request notable changes Used for release notes to highlight these more highly labels Oct 31, 2026
OpenAPI 3.2 adds the fixed `query` operation (HTTP QUERY) and an
`additionalOperations` map of arbitrary HTTP methods to the Path Item.
kin-openapi v0.152.0 already surfaces both through PathItem.Operations(),
so the generator picked them up everywhere except route registration,
where the per-method router shortcuts (router.Get, router.GET, ...) do
not exist for these methods.

Route registration now falls back to each router's string-method API
for any non-standard method: chi.MethodFunc, echo Add, gin Handle,
fiber Add (v2 single method, v3 slice), iris Handle. net/http,
gorilla/mux and the client already took the method as a string. The
echo EchoRouter interface gains an Add method only when the spec uses
a custom method, so existing specs keep the same interface. gin's
CONNECT and TRACE also go through Handle now; gin has no shortcut for
them and the previous output did not compile.

Routers that only accept methods they have been told about (chi via
chi.RegisterMethod, fiber via Config.RequestMethods) are deliberately
not set up by the generated code: that state is process-wide, and one
process commonly hosts several generated packages. The README and the
per-router docs describe the one-time startup step instead; iris is
documented as needing nothing.

A new conformance fixture generates a 3.2 spec with GET, QUERY and a
custom PURGE for every server framework plus the client, and its test
drives real QUERY/PURGE requests through each router. Regenerating the
repo leaves all pre-existing generated files byte-identical.

Closes oapi-codegen#2436

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects generated routing for OpenAPI 3.2 methods across supported server frameworks.

The PR appears safe to merge, with a non-blocking fix recommended for repeated test runs.

Findings

  1. P2 Repeated Chi tests fail ▶
Fix with agent prompt
### Issue 1
internal/test/servers/routers/methods/methods_test.go:115-120
`TestChi` fails when repeated in the same process, such as with `go test -count=2 ./servers/routers/methods` from `internal/test`. The first run registers `QUERY` and `PURGE` process-wide. On the second run, `chiapi.Handler` no longer panics, so the opening `assert.Panics` fails even though routing works. Run the unregistered-method check in a fresh subprocess so it does not depend on shared state.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds route registration for OpenAPI 3.2 query and additionalOperations across the supported server frameworks.

  • Generated servers register OpenAPI 3.2 methods through each router’s generic method API.

Acknowledged intentional choices from mromaszewicz: custom-method setup stays in the application because it affects shared state; Echo’s generated EchoRouter gains Add only for affected specs.

Reviews (1) · Last reviewed commit: "feat: support OpenAPI 3.2 QUERY and addi..." · Reviewed by Greptile

@mromaszewicz
mromaszewicz merged commit 946e731 into oapi-codegen:main Oct 31, 2026
14 checks passed
@mromaszewicz
mromaszewicz deleted the feat/issue-2436 branch October 31, 2026 20:27
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.

Support for OpenAPI 3.2?

1 participant