GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: resolve Go field name collisions when JSON keys differ only by separator (#2495) by rifkir23 · Pull Request #2550 · oapi-codegen/oapi-codegen ConversationProblemWhen two JSON properties in the same object differ only by their separator — e.g. This is reproducible against real specs (the issue references the Tenable Vulnerability Management API, whose Fixes #2495 FixResolve Go field-name collisions within a struct in Only the Go identifier changes — the JSON struct tag still uses the original TestsAdded
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Prompt To Fix All With AI### Issue 1 pkg/codegen/schema.go:1657-1661 **Boilerplate uses unresolved field names** When a union or additional-properties object contains properties such as `host-fqdn` and `host_fqdn`, the struct declares the latter as `HostFqdn2`, but generated marshal/unmarshal templates still resolve both accesses as `HostFqdn`, causing the second JSON property to read from or write to the wrong Go field. ### Issue 2 pkg/codegen/schema.go:1779-1784 **Synthetic field collision remains** When an object allows additional properties and also declares a property named `additionalProperties` or uses `x-go-name: AdditionalProperties`, the resolver does not reserve the synthetic field name, so `GenStructFromSchema` emits two `AdditionalProperties` fields and the generated Go code fails to compile. --- For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. Reviews (1): Last reviewed commit: "fix: resolve Go field name collisions wh..." | Re-trigger Greptile All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+1657
to
+1661
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a union or additional-properties object contains properties such as Knowledge Base Used: Schema and Go model generation Prompt To Fix With AIThis is a comment left during a code review. Path: pkg/codegen/schema.go Line: 1657-1661 Comment: **Boilerplate uses unresolved field names** When a union or additional-properties object contains properties such as `host-fqdn` and `host_fqdn`, the struct declares the latter as `HostFqdn2`, but generated marshal/unmarshal templates still resolve both accesses as `HostFqdn`, causing the second JSON property to read from or write to the wrong Go field. **Knowledge Base Used:** [Schema and Go model generation](https://app.greptile.com/oapi-codegen/-/custom-context/knowledge-base/oapi-codegen/oapi-codegen/-/docs/schema-and-model-generation.md) --- For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+1779
to
+1784
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an object allows additional properties and also declares a property named Knowledge Base Used: Prompt To Fix With AIThis is a comment left during a code review. Path: pkg/codegen/schema.go Line: 1779-1784 Comment: **Synthetic field collision remains** When an object allows additional properties and also declares a property named `additionalProperties` or uses `x-go-name: AdditionalProperties`, the resolver does not reserve the synthetic field name, so `GenStructFromSchema` emits two `AdditionalProperties` fields and the generated Go code fails to compile. **Knowledge Base Used:** - [Schema and Go model generation](https://app.greptile.com/oapi-codegen/-/custom-context/knowledge-base/oapi-codegen/oapi-codegen/-/docs/schema-and-model-generation.md) - [Name shared path parameter helpers safely](https://app.greptile.com/oapi-codegen/-/custom-context/knowledge-base/oapi-codegen/oapi-codegen/-/reverts/revert_2476-20260716-shared-path-parameter-collision-bd52535.md) --- For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…eparator (oapi-codegen#2495) Move collision resolution from GenFieldsFromProperties to a single-source resolver (ResolvePropertyGoFieldNameCollisions) that populates an unexported resolvedGoFieldName on each Property. GoFieldName() now returns the resolved name, so the struct declaration AND the generated marshal/unmarshal boilerplate (union, additional-properties templates) all share the same disambiguated field name. Also reserves the synthetic AdditionalProperties field name so a real property named 'additionalProperties' does not collide with it. Fixes oapi-codegen#2495
rifkir23
force-pushed
the
fix/field-name-collision-hyphen-underscore
branch
from
ba4b9de to
c1eb68a
Compare
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersAt least 1 approving review is required to merge this pull request. Uh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. oapi-codegen v2 produces duplicate Go field names when JSON keys differ only by separator (hyphen vs underscore)Uh oh!
There was an error while loading. Please reload this page. 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. | ||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |