kubernetes / kube-openapi

Kubernetes OpenAPI spec generation & serving
Apache License 2.0
319 stars 208 forks source link

Bug: +enum type used in array is not reflected in Schema #450

Closed alexzielenski closed 8 months ago

alexzielenski commented 9 months ago

I've been testing our some of our marker comments on native types. I've found an issue where having an array with +enum does not result in the items of the array validating the enum.

/cc @jiahuif

Example:

https://github.com/kubernetes/kubernetes/blob/7ec1a89a509906dad9fd6a4635d7bfc157b47790/staging/src/k8s.io/api/core/v1/types.go#L331-L335

PersistentVolumeSpec.AccessModes above is a []PersistentVolumeAccessMode. This type is tagged with +enum.

Unfortunately the generated OpenAPI does not include (can't direct link line in large file) the enum values in the items for this field:


func schema_k8sio_api_core_v1_PersistentVolumeSpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
    return common.OpenAPIDefinition{
        Schema: spec.Schema{
            SchemaProps: spec.SchemaProps{
                Description: "PersistentVolumeSpec is the specification of a persistent volume.",
                Type:        []string{"object"},
                Properties: map[string]spec.Schema{
                    ...
                    "accessModes": {
                        VendorExtensible: spec.VendorExtensible{
                            Extensions: spec.Extensions{
                                "x-kubernetes-list-type": "atomic",
                            },
                        },
                        SchemaProps: spec.SchemaProps{
                            Description: "accessModes contains all ways the volume can be mounted. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes",
                            Type:        []string{"array"},
                            Items: &spec.SchemaOrArray{
                                Schema: &spec.Schema{
                                    SchemaProps: spec.SchemaProps{
                                        Default: "",
                                        Type:    []string{"string"},
                                        Format:  "",
                                    },
                                },
                            },
                        },
                    },
...
}