Skip to content

[Go]: Avoid name collisions of case-sensitive properties - #24624

Closed
thiagoarrais wants to merge 1 commit into
OpenAPITools:masterfrom
thiagoarrais:case-sensitive-props
Closed

[Go]: Avoid name collisions of case-sensitive properties#24624
thiagoarrais wants to merge 1 commit into
OpenAPITools:masterfrom
thiagoarrais:case-sensitive-props

Conversation

@thiagoarrais

@thiagoarrais thiagoarrais commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

This PR changes the Go generator to avoid possible name collisions due to case-sensitive object property names. The input spec may specify two properties named Foo and foo, and the generated Go code would (before this PR) include two fields named Foo in the same struct.

This may be applicable to other languages as well.

Golang committee: @antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @lwj5

PR checklist


Summary by cubic

Fixes Go code generation to prevent struct field collisions when properties differ only by case. Conflicting fields now get a stable P_ prefix so the generated code compiles and remains unambiguous.

  • Bug Fixes

    • Detect collisions on Go field names and rename duplicates to P_<baseName>.
    • Mark renamed fields as sanitized to reflect the change.
    • Added a unit test covering name, Name, FirstName, first_name -> Name, P_Name, FirstName, P_first_name.
  • Migration

    • If your schema defines case-sensitive duplicates, the generated Go field names may change to P_<baseName>. Update any references accordingly.

Written for commit b126649. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor

I believe the best approach is to use the already existing name-mapping setting to handle these scenarios.

@thiagoarrais

Copy link
Copy Markdown
Contributor Author

Closing in favor of name-mapping (pointed by @Mattias-Sehlstedt)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants