Skip to content

fix: render Godoc correctly for renamed + union types#2451

Merged
jamietanna merged 2 commits into
mainfrom
fix/comment
Jul 12, 2026
Merged

fix: render Godoc correctly for renamed + union types#2451
jamietanna merged 2 commits into
mainfrom
fix/comment

Conversation

@jamietanna

@jamietanna jamietanna commented Jul 12, 2026

Copy link
Copy Markdown
Member

As otherwise we see defines model for ., which isn't correct.

@jamietanna jamietanna changed the title fix: render Godoc correctly for renamed types fix: render Godoc correctly for renamed + union types Jul 12, 2026
@jamietanna
jamietanna marked this pull request as ready for review July 12, 2026 14:32
@jamietanna
jamietanna requested a review from a team as a code owner July 12, 2026 14:32
@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes missing JsonName assignments on TypeDefinition structs in two code paths in pkg/codegen/schema.go, which caused generated Godoc comments to read defines model for . instead of the correct schema path.

  • In GenerateGoSchema, the TypeDefinition created for x-go-type-name-renamed types now sets JsonName: strings.Join(path, "."), so renamed types like ClientRenamedByExtension correctly document as defines model for ClientWithExtension.
  • In generateUnion, the TypeDefinition created for inline (non-$ref) union elements now sets JsonName: strings.Join(elementPath, "."), so synthesised variant types like ParamAnyOf0 correctly document as defines model for ParamAnyOf.0.
  • All affected *.gen.go fixture files have been regenerated; the diff is consistent with the stated fix and shows no unrelated churn.

Confidence Score: 5/5

Safe to merge — the only changes are two one-line additions that populate a Godoc string field, and all regenerated fixture files reflect exactly those additions with no unrelated drift.

The fix is narrowly scoped to Godoc comment generation: two previously-empty JsonName fields are now populated, and every affected fixture file regenerates correctly. No Go type shapes, struct tags, function signatures, or runtime behavior are altered.

No files require special attention.

Important Files Changed

Filename Overview
pkg/codegen/schema.go Adds missing JsonName field in two TypeDefinition construction sites: the x-go-type-name extension path and the generateUnion inline-element path, fixing the "defines model for ." Godoc bug.
examples/extensions/xgotypename/gen.go Regenerated output; comment for ClientRenamedByExtension now correctly reads "defines model for ClientWithExtension." instead of "defines model for ."
internal/test/aggregates/anyof/anyof.gen.go Regenerated; union-element type comments now include the correct parent.index path (e.g. "ParamAnyOf.0").
internal/test/aggregates/hoisting/hoisting_schemas.gen.go Regenerated; hoisted anonymous inner type comment now reads "defines model for OuterTypeWithAnonymousInner.inner."
internal/test/aggregates/oneof/components.gen.go Regenerated; all oneOf element type comments updated with correct parent.index paths.
internal/test/extensions/x_go_type/x_go_type.gen.go Regenerated; MyTestRequest comment now correctly reads "defines model for Test." for the x-go-type-name renamed type.
internal/test/naming/conflicts/conflicts.gen.go Regenerated; CustomQux and several union alias comments now have correct model paths.
internal/test/schemas/recursive/recursive.gen.go Regenerated; all recursive union-element aliases (FilterPredicate1, FilterRangeValue0, etc.) now have correct model path comments.
internal/test/options/name_normalizer/to_camel_case/name_normalizer.gen.go Regenerated; OneOf2things0 and OneOf2things1 union-element comments now include correct parent.index paths.
internal/test/options/name_normalizer/to_camel_case_with_additional_initialisms/name_normalizer.gen.go Regenerated; same union-element Godoc fix as the other name_normalizer variants.
internal/test/options/name_normalizer/to_camel_case_with_digits/name_normalizer.gen.go Regenerated; same union-element Godoc fix as the other name_normalizer variants.
internal/test/options/name_normalizer/to_camel_case_with_initialisms/name_normalizer.gen.go Regenerated; same union-element Godoc fix as the other name_normalizer variants.
internal/test/options/name_normalizer/unset/name_normalizer.gen.go Regenerated; same union-element Godoc fix as the other name_normalizer variants.

Reviews (1): Last reviewed commit: "fix: render Godoc correctly for union ty..." | Re-trigger Greptile

@jamietanna jamietanna added the bug Something isn't working label Jul 12, 2026
jamietanna and others added 2 commits July 12, 2026 15:38
As otherwise we see `defines model for .`, which isn't correct.

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@rootly.com>
As otherwise we see `defines model for .`, which isn't correct.

This isn't the best rendered output but improves our output for now.

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@rootly.com>
@jamietanna

Copy link
Copy Markdown
Member Author

IMO, we should review this Godoc and improve it - I'm not quite sure if this is as effective/useful as it could be

@jamietanna
jamietanna merged commit 9e29f17 into main Jul 12, 2026
28 checks passed
@jamietanna
jamietanna deleted the fix/comment branch July 12, 2026 14:42
@mromaszewicz

Copy link
Copy Markdown
Member

I agree. It's not very useful. It's very, very old code. It would be nice if it referred to the exact place in the spec that it came from, for example.

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.

2 participants