Skip to content

openapi-gen ignores +listType/+listMapKey markers on named slice types (type Foo []Bar), emitting atomic lists #630

Description

@npinaeva

+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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions