Fix duplicate map keys when a type embeds two structs sharing a field - #631
Fix duplicate map keys when a type embeds two structs sharing a field#631HarnageaGabriel wants to merge 1 commit into
Conversation
generateMembers recursed into embedded members without tracking which field names had already been emitted. When two different embedded types provided a field with the same name (e.g. both indirectly embed metav1.TypeMeta, both exposing "kind"/"apiVersion"), generateProperty was invoked twice for that name, producing a Go map literal with a duplicate key in the generated zz_generated.openapi.go, which fails to compile. Resolve embedded fields breadth-first by depth, matching Go's own embedding rules: a field at a shallower depth wins over one deeper, and two fields tying at the same shallowest depth are ambiguous and excluded entirely (mirroring Go's unpromoted-ambiguous-selector behavior) instead of silently duplicating a key. Fixes kubernetes#129
|
|
|
Welcome @HarnageaGabriel! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: HarnageaGabriel The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary
generateMembersrecursed into embedded struct members without tracking which field names it had already emitted. When a type embeds two different structs that (directly or transitively) provide a field with the same name — e.g. both indirectly embedmetav1.TypeMeta, both exposingkind/apiVersion—generatePropertywas called twice for that name. That produced a Go map literal in the generatedzz_generated.openapi.gowith a duplicate key, which fails to compile:This mirrors the case reported in #129 (
ServiceServingCertSignerConfigembedding two types that both embeddedmetav1.TypeMeta).Fix
generateMembersnow resolves embedded fields breadth-first by depth, matching Go's own field-promotion rules:requiredfield list is deduplicated the same wayTest plan
go build ./...go test ./pkg/generators/...(255 tests passed)PropertiesandRequired), and a shallower embed's field winning over a deeper one with the same nameFixes #129