Skip to content

Add sort-handler-registrations flag to opt out of spec-order registra…#2477

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-1887
Jul 17, 2026
Merged

Add sort-handler-registrations flag to opt out of spec-order registra…#2477
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-1887

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

…tion

PR #2465 (issue #1887) changed generated servers to register route handlers in spec-declaration order, so that routers which match in registration order (Fiber, Gorilla/mux) can disambiguate overlapping paths by ordering them in the spec. This makes that behavior opt-out: the new sort-handler-registrations compatibility flag restores the historical lexicographic (by path, then method) registration order for users who relied on it.

The dispatch is a single seam -- operationsInRegistrationOrder picks sortOperationsLexicographically when the flag is set, otherwise the existing sortOperationsBySpecOrder -- and all nine GenerateXServer functions route through it. The lexicographic sort reproduces the historical gather order (SortedMapKeys over paths then methods), so with the flag unset the default output is unchanged.

Adds TestSortHandlerRegistrations and documents the flag in configuration-schema.json.

@mromaszewicz mromaszewicz added the bug Something isn't working label Jul 17, 2026
@mromaszewicz
mromaszewicz requested a review from a team as a code owner July 17, 2026 13:51
@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an opt-out flag for server route registration order. The main changes are:

  • New sort-handler-registrations compatibility config and schema entry.
  • Shared registration-order helper for all generated server backends.
  • Regression coverage for default spec order and opt-in lexicographic order.

Confidence Score: 5/5

The changed flow looks safe to merge after a small documentation cleanup.

  • The config field, schema entry, default behavior, and generation dispatch line up.
  • All server registration generators use the same ordering helper.
  • The remaining issue is discoverability for the new flag in the configuration reference.

docs/configuration.md

Important Files Changed

Filename Overview
configuration-schema.json Adds the new compatibility flag to the JSON schema with a matching boolean shape.
pkg/codegen/configuration.go Adds the Go config field for the new compatibility flag; the config reference still needs the matching documentation update.
pkg/codegen/operations.go Adds the lexicographic ordering helper and routes all server registration generators through the shared dispatch.
pkg/codegen/codegen_test.go Adds a focused test for default spec-order registration and opt-in lexicographic registration.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
pkg/codegen/configuration.go:398
**Compatibility Flag Is Undocumented**

The new `sort-handler-registrations` option is accepted by the Go config and schema, but the hand-maintained configuration reference still omits it from the compatibility options list. Users relying on that reference will not discover the opt-out and can keep generating spec-order route registrations when they need the historical lexicographic order.

Reviews (1): Last reviewed commit: "Add sort-handler-registrations flag to o..." | Re-trigger Greptile

Comment thread pkg/codegen/configuration.go
…tion

PR oapi-codegen#2465 (issue oapi-codegen#1887) changed generated servers to register route handlers in
spec-declaration order, so that routers which match in registration order
(Fiber, Gorilla/mux) can disambiguate overlapping paths by ordering them in the
spec. This makes that behavior opt-out: the new sort-handler-registrations
compatibility flag restores the historical lexicographic (by path, then method)
registration order for users who relied on it.

The dispatch is a single seam -- operationsInRegistrationOrder picks
sortOperationsLexicographically when the flag is set, otherwise the existing
sortOperationsBySpecOrder -- and all nine GenerateXServer functions route
through it. The lexicographic sort reproduces the historical gather order
(SortedMapKeys over paths then methods), so with the flag unset the default
output is unchanged.

Adds TestSortHandlerRegistrations and documents the flag in
configuration-schema.json.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mromaszewicz
mromaszewicz merged commit de2d8b2 into oapi-codegen:main Jul 17, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant