Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove validation for default value against pattern #959

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions libs/jsonschema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
13 changes: 1 addition & 12 deletions libs/jsonschema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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())
}

Expand Down