Skip to content

Commit 283f241

Browse files
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 #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: databricks/mlops-stacks#108 Note, this does not remove runtime validation for input parameters right before template initialization, which happens here: https://github.com/databricks/cli/blob/fb32e78c9b9fb000ce898b8a60b0b47920f487d3/libs/template/materialize.go#L76 ## Tests Changes to existing test.
1 parent 677f28e commit 283f241

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

libs/jsonschema/schema.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ func (schema *Schema) validateSchemaPattern() error {
168168
return fmt.Errorf("invalid regex pattern %q provided for property %q: %w", pattern, name, err)
169169
}
170170

171-
// validate default value against the pattern
172-
if property.Default != nil && !r.MatchString(property.Default.(string)) {
173-
return fmt.Errorf("default value %q for property %q does not match specified regex pattern: %q", property.Default, name, pattern)
174-
}
175-
176171
// validate enum values against the pattern
177172
for i, enum := range property.Enum {
178173
if !r.MatchString(enum.(string)) {

libs/jsonschema/schema_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestSchemaValidateIncorrectRegex(t *testing.T) {
175175
assert.EqualError(t, s.validate(), "invalid regex pattern \"(abc\" provided for property \"foo\": error parsing regexp: missing closing ): `(abc`")
176176
}
177177

178-
func TestSchemaValidatePatternDefault(t *testing.T) {
178+
func TestSchemaDefaultValueIsNotValidatedAgainstPattern(t *testing.T) {
179179
s := &Schema{
180180
Properties: map[string]*Schema{
181181
"foo": {
@@ -185,17 +185,6 @@ func TestSchemaValidatePatternDefault(t *testing.T) {
185185
},
186186
},
187187
}
188-
assert.EqualError(t, s.validate(), "default value \"def\" for property \"foo\" does not match specified regex pattern: \"abc\"")
189-
190-
s = &Schema{
191-
Properties: map[string]*Schema{
192-
"foo": {
193-
Type: "string",
194-
Pattern: "a.*d",
195-
Default: "axyzd",
196-
},
197-
},
198-
}
199188
assert.NoError(t, s.validate())
200189
}
201190

0 commit comments

Comments
 (0)