diff --git a/pkg/schema.go b/pkg/schema.go index 516b0e8..313ecc6 100644 --- a/pkg/schema.go +++ b/pkg/schema.go @@ -26,6 +26,7 @@ type Schema struct { PatternProperties interface{} `json:"patternProperties,omitempty"` Required []string `json:"required,omitempty"` Items *Schema `json:"items,omitempty"` + ItemsEnum []any `json:"itemsEnum,omitempty"` Properties map[string]*Schema `json:"properties,omitempty"` Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` @@ -187,6 +188,11 @@ func processComment(schema *Schema, comment string) (isRequired bool) { schema.Items = &Schema{ Type: value, } + case "itemEnum": + if schema.Items == nil { + schema.Items = &Schema{} + } + schema.Items.Enum = processList(value, false) case "additionalProperties": if v, err := strconv.ParseBool(value); err == nil { schema.AdditionalProperties = &v diff --git a/pkg/schema_test.go b/pkg/schema_test.go index a647bd6..286b8bd 100644 --- a/pkg/schema_test.go +++ b/pkg/schema_test.go @@ -301,6 +301,13 @@ func TestProcessComment(t *testing.T) { expectedSchema: &Schema{MinItems: uint64Ptr(1), MaxItems: uint64Ptr(10), UniqueItems: true, Items: &Schema{Type: "boolean"}}, expectedRequired: false, }, + { + name: "Set array item enum", + schema: &Schema{}, + comment: "# @schema minItems:1;maxItems:10;uniqueItems:true;item:boolean;itemEnum:[\"one\",\"two\"]", + expectedSchema: &Schema{MinItems: uint64Ptr(1), MaxItems: uint64Ptr(10), UniqueItems: true, Items: &Schema{Type: "boolean", Enum: []any{"one", "two"}}}, + expectedRequired: false, + }, { name: "Set object", schema: &Schema{},