Remove validation for default value against pattern (#959)

## Changes
This PR removes validation for default value against the regex pattern
specified in a JSON schema at schema load time. This is required because
https://github.com/databricks/cli/pull/795 introduces parameterising the
default value as a Go text template impling that the default value now
does not necessarily have to match the pattern at schema load time.

This will also unblock:
https://github.com/databricks/mlops-stacks/pull/108

Note, this does not remove runtime validation for input parameters right
before template initialization, which happens here:
fb32e78c9b/libs/template/materialize.go (L76)

## Tests
Changes to existing test.
This commit is contained in:
shreyas-goenka 2023-11-07 13:35:59 +01:00 committed by GitHub
parent 677f28e2fb
commit 283f24179d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 17 deletions

View File

@ -168,11 +168,6 @@ func (schema *Schema) validateSchemaPattern() error {
return fmt.Errorf("invalid regex pattern %q provided for property %q: %w", pattern, name, err)
}
// validate default value against the pattern
if property.Default != nil && !r.MatchString(property.Default.(string)) {
return fmt.Errorf("default value %q for property %q does not match specified regex pattern: %q", property.Default, name, pattern)
}
// validate enum values against the pattern
for i, enum := range property.Enum {
if !r.MatchString(enum.(string)) {

View File

@ -175,7 +175,7 @@ func TestSchemaValidateIncorrectRegex(t *testing.T) {
assert.EqualError(t, s.validate(), "invalid regex pattern \"(abc\" provided for property \"foo\": error parsing regexp: missing closing ): `(abc`")
}
func TestSchemaValidatePatternDefault(t *testing.T) {
func TestSchemaDefaultValueIsNotValidatedAgainstPattern(t *testing.T) {
s := &Schema{
Properties: map[string]*Schema{
"foo": {
@ -185,17 +185,6 @@ func TestSchemaValidatePatternDefault(t *testing.T) {
},
},
}
assert.EqualError(t, s.validate(), "default value \"def\" for property \"foo\" does not match specified regex pattern: \"abc\"")
s = &Schema{
Properties: map[string]*Schema{
"foo": {
Type: "string",
Pattern: "a.*d",
Default: "axyzd",
},
},
}
assert.NoError(t, s.validate())
}