You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug - inconsistent underscore handling for property names in 2.5.0 #2032
Hmm, so this is an interesting one because of the mixed case - the Underscore prefix goes through the name-normalizer Output Option, which doesn't know that this specific field is intended to be SNAKE_CASE.
As a short-term, using x-go-name and x-oapi-codegen-only-honour-go-namevia should give you the ability to override it locally, and continue to use v2.5.0
Will have a think about how best to handle this, given the default would be to use PascalCase (which we refer to as CamelCase, incorrectly 🫣)
The Underscore prefix was added in 2.5.0 so that _id and id in the same object would not end up as the same field. With drop, that case is reported as an error naming both properties; you can rename one of them with x-go-name, or set output-options.resolve-type-name-collisions: true to have them renamed automatically.
The option is opt-in, so nothing changes unless you set it. It will be released in v2.9.0. Until then you need to use the main branch, for example:
go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@main --config=config.yaml spec.yaml
Activity
jamietanna commentedon Jul 16, 2025
Hmm, so this is an interesting one because of the mixed case - the
Underscoreprefix goes through thename-normalizerOutput Option, which doesn't know that this specific field is intended to be SNAKE_CASE.As a short-term, using
x-go-nameandx-oapi-codegen-only-honour-go-namevia should give you the ability to override it locally, and continue to use v2.5.0Will have a think about how best to handle this, given the default would be to use PascalCase (which we refer to as CamelCase, incorrectly 🫣)
mromaszewicz commentedon Nov 21, 2026
As of #2683 there is an opt-in setting that brings back the pre-2.5.0 field names for properties that start with an underscore.
Add this to your configuration:
With a property like the one in this issue:
the generated code is now:
The
Underscoreprefix was added in 2.5.0 so that_idandidin the same object would not end up as the same field. Withdrop, that case is reported as an error naming both properties; you can rename one of them withx-go-name, or setoutput-options.resolve-type-name-collisions: trueto have them renamed automatically.The option is opt-in, so nothing changes unless you set it. It will be released in v2.9.0. Until then you need to use the
mainbranch, for example:The other naming options are described in the README under Adjusting how names are normalized.