+listType=map / +listMapKey placed on a named slice type declaration (type Foo []Bar) is honored by controller-gen (CRD gets
x-kubernetes-list-type: map) but dropped by openapi-gen — so the apply/structured-merge-diff schema produced by applyconfiguration-gen comes out atomic. When the identical marker is placed on the struct field, all three generators agree.
// +listType=map
// +listMapKey=key
type SelectorsA []Selector // marker on the type
type Spec struct {
SelectorsFromType SelectorsA `json:"selectorsFromType,omitempty"`
// +listType=map
// +listMapKey=key
SelectorsOnField []Selector `json:"selectorsOnField,omitempty"` // marker on the FIELD
}
Full CRD is here https://github.com/npinaeva/openapi-bug/blob/main/api/v1/types.go
CRD is generated correctly https://github.com/npinaeva/openapi-bug/blob/main/crds/example.io_examples.yaml
selectorsFromType:
...
x-kubernetes-list-map-keys: [key]
x-kubernetes-list-type: map
selectorsOnField:
...
x-kubernetes-list-map-keys: [key]
x-kubernetes-list-type: map
But openapi-gen dropped the type marker
https://github.com/npinaeva/openapi-bug/blob/main/api/v1/openapi/zz_generated.openapi.go
Properties: map[string]spec.Schema{
"selectorsFromType": {
SchemaProps: spec.SchemaProps{
Description: "Variant A: field references a named slice type whose *type* carries the markers.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Ref: ref(v1.Selector{}.OpenAPIModelName()),
},
},
},
},
},
"selectorsOnField": {
VendorExtensible: spec.VendorExtensible{
Extensions: spec.Extensions{
"x-kubernetes-list-map-keys": []interface{}{
"key",
},
"x-kubernetes-list-type": "map",
},
},
SchemaProps: spec.SchemaProps{
Description: "Variant B: same element type, but markers on the FIELD.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Ref: ref(v1.Selector{}.OpenAPIModelName()),
},
},
},
},
},
},
Looks like
|
func (g openAPITypeWriter) generateMemberExtensions(m *types.Member, parent *types.Type, otherExtensions map[string]interface{}) error { |
ignores aliases
+listType=map/+listMapKeyplaced on a named slice type declaration (type Foo []Bar) is honored by controller-gen (CRD getsx-kubernetes-list-type: map) but dropped by openapi-gen — so the apply/structured-merge-diff schema produced by applyconfiguration-gen comes outatomic. When the identical marker is placed on the struct field, all three generators agree.Full CRD is here https://github.com/npinaeva/openapi-bug/blob/main/api/v1/types.go
CRD is generated correctly https://github.com/npinaeva/openapi-bug/blob/main/crds/example.io_examples.yaml
But
openapi-gendropped the type markerhttps://github.com/npinaeva/openapi-bug/blob/main/api/v1/openapi/zz_generated.openapi.go
Looks like
kube-openapi/pkg/generators/openapi.go
Line 756 in d427ff9