Repository navigation
fix(gen): apply x-ogen-name to external types (x-ogen-type) - #1697
Merged
Merged
Conversation
A component schema combining x-ogen-type (external Go type mapping) and x-ogen-name (type name override) ignored x-ogen-name: the generated type used the component key (e.g. "usdAmount" -> UsdAmount) instead of the override (USDAmount). The x-ogen-type branch in schemaGen.generate2 builds the external type and returns early, before the name override below it was reached. Move the name resolution above that branch so it always applies; the intervening DefaultSet and UniqueItems checks do not depend on name, so behavior for other schemas is unchanged. Add a component-schema case (x-ogen-type + x-ogen-name) to _testdata/positive/type_extension_name.yml and a regression test, regenerate the golden package. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
oha-4
force-pushed
the
fix/x-ogen-name-external-type
branch
from
June 18, 2026 12:42
670180e to
a70b518
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A component schema combining
x-ogen-type(external Go type mapping) andx-ogen-name(type name override) ignoresx-ogen-name. The generated type is named after the component key instead of the override.type USDAmount money.Decimaltype UsdAmount money.Decimal(PascalCase of the keyusdAmount;x-ogen-nameignored)x-ogen-nameworks for plain (non-external) schemas — only external types were affected.Cause
In
schemaGen.generate2(gen/schema_gen.go), thex-ogen-typebranch builds the external type and returns early, before the name-override block below it is reached. So the name stays the component-key-derived one.Fix
Move the name resolution above the
x-ogen-typebranch so it always applies. The interveningDefaultSetandUniqueItemschecks do not depend onname, so behavior for all other schemas is unchanged.A side effect: external types now also get the
Rprefix for digit-leading names (previously skipped via the early return) — this only turns a previously-invalid Go identifier into a valid one.Tests
x-ogen-type+x-ogen-name) to_testdata/positive/type_extension_name.yml. The schema keyusdAmountPascalCases toUsdAmount, whilex-ogen-name: USDAmountis the Go-idiomatic spelling; the test reuses an existing testdata external type to avoid adding a dependency.TestTypeExtensionName_JSON/Component).go generate ./...changes only thetest_type_extension_namepackage; no other golden output is affected.Before / after (generated)
🤖 Generated with Claude Code