Skip to content

Commit

Permalink
Set Items type in array with schema annotation
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Stojanov <[email protected]>
  • Loading branch information
losisin committed Mar 11, 2024
1 parent d663707 commit a6bc339
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ func processComment(schema *Schema, comment string) (isRequired bool) {
if err := json.Unmarshal([]byte(value), &jsonObject); err == nil {
schema.Default = jsonObject
}
case "item":
schema.Items = &Schema{
Type: value,
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ func TestProcessComment(t *testing.T) {
{
name: "Set array",
schema: &Schema{},
comment: "# @schema minItems:1;maxItems:10;uniqueItems:true",
expectedSchema: &Schema{MinItems: uint64Ptr(1), MaxItems: uint64Ptr(10), UniqueItems: true},
comment: "# @schema minItems:1;maxItems:10;uniqueItems:true;item:boolean",
expectedSchema: &Schema{MinItems: uint64Ptr(1), MaxItems: uint64Ptr(10), UniqueItems: true, Items: &Schema{Type: "boolean"}},
expectedRequired: false,
},
{
Expand Down
6 changes: 6 additions & 0 deletions testdata/full.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
],
"type": "object"
},
"imagePullSecrets": {
"items": {
"type": "object"
},
"type": "array"
},
"nameOverride": {
"type": "string"
},
Expand Down
2 changes: 2 additions & 0 deletions testdata/full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ replicas: 2 # @schema minimum: 1 ; maximum: 10 ; multipleOf: 2
fullnameOverride: bar # @schema pattern: ^[a-z]$ ; title: My title

# Arrays
imagePullSecrets: [] # @schema item: object

tolerations: # @schema minItems: 1 ; maxItems: 10 ; uniqueItems: true
- key: "bar"
operator: "Equal"
Expand Down

0 comments on commit a6bc339

Please sign in to comment.