Support for enum within an array
Hi everyone,
I was looking for a way to support the following json schema:
"properties": {
"allowedResources": {
"description": "the list of resources that are allowed to be children of this widget or referenced by it",
"type": "array",
"items": {
"type": "string",
"enum": [
"barcharts",
"buttons",
"eventlists",
"filters",
"flowcharts",
"forms",
"linecharts",
"markdowns",
"panels",
"paragraphs",
"piecharts",
"tables",
"tablists",
"yamlviewers"
]
}
}
Is there a marker that allows this use case?
Thanks for any feedback!
You should be able to create a string type alias and then use that as the list element type
// +kubebuilder:validation:Enum:=A;B;C
type Foo string
...
// foos is a list of Foos.
// Valid options are A, B and C.
Foos []Foo `json:"foo,omitempty"
@JoelSpeed is there another way to avoid alias in code? I would like to avoid this manual approach.
Not presently that I'm aware of no. In upstream/core Kube types, all enums are type aliases like this. It's useful when coding, for example, when you build a switch, linters can check you've handled all potential values
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale