Skip to content

Commit

Permalink
Allow pattern usage for IntOrString fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelSpeed committed Sep 3, 2021
1 parent af6ac5f commit 62703ca
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/crd/markers/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,11 @@ func (m MinLength) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
return nil
}
func (m Pattern) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
if schema.Type != "string" {
return fmt.Errorf("must apply pattern to a string")
// Allow string types or IntOrStrings. An IntOrString will still
// apply the pattern validation when a string is detected, the pattern
// will not apply to ints though.
if schema.Type != "string" || schema.XIntOrString {
return fmt.Errorf("must apply pattern to a `string` or `IntOrString`")
}
schema.Pattern = string(m)
return nil
Expand Down

0 comments on commit 62703ca

Please sign in to comment.