Content-Length: 321990 | pFad | https://togithub.com/losisin/helm-values-schema-json/commit/c08b884

67A Add: option to apply enum on array items · losisin/helm-values-schema-json@c08b884 · GitHub
Skip to content

Commit c08b884

Browse files
committed
Add: option to apply enum on array items
1 parent 710fd2f commit c08b884

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/schema.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Schema struct {
2626
PatternProperties interface{} `json:"patternProperties,omitempty"`
2727
Required []string `json:"required,omitempty"`
2828
Items *Schema `json:"items,omitempty"`
29+
ItemsEnum []any `json:"itemsEnum,omitempty"`
2930
Properties map[string]*Schema `json:"properties,omitempty"`
3031
Title string `json:"title,omitempty"`
3132
Description string `json:"description,omitempty"`
@@ -187,6 +188,11 @@ func processComment(schema *Schema, comment string) (isRequired bool) {
187188
schema.Items = &Schema{
188189
Type: value,
189190
}
191+
case "itemEnum":
192+
if schema.Items == nil {
193+
schema.Items = &Schema{}
194+
}
195+
schema.Items.Enum = processList(value, false)
190196
case "additionalProperties":
191197
if v, err := strconv.ParseBool(value); err == nil {
192198
schema.AdditionalProperties = &v

pkg/schema_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ func TestProcessComment(t *testing.T) {
301301
expectedSchema: &Schema{MinItems: uint64Ptr(1), MaxItems: uint64Ptr(10), UniqueItems: true, Items: &Schema{Type: "boolean"}},
302302
expectedRequired: false,
303303
},
304+
{
305+
name: "Set array item enum",
306+
schema: &Schema{},
307+
comment: "# @schema minItems:1;maxItems:10;uniqueItems:true;item:boolean;itemEnum:[\"one\",\"two\"]",
308+
expectedSchema: &Schema{MinItems: uint64Ptr(1), MaxItems: uint64Ptr(10), UniqueItems: true, Items: &Schema{Type: "boolean", Enum: []any{"one", "two"}}},
309+
expectedRequired: false,
310+
},
304311
{
305312
name: "Set object",
306313
schema: &Schema{},

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://togithub.com/losisin/helm-values-schema-json/commit/c08b884

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy