Skip to content

Allow pattern on array items to contain equals sign #137

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion fixtures/equals_in_pattern.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
"WithEqualsAndCommas": {
"type": "string",
"pattern": "foo,=bar"
},
"WithEqualsArray": {
"items": {
"type": "string",
"pattern": "foo=bar"
},
"type": "array"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"WithEquals",
"WithEqualsAndCommas"
"WithEqualsAndCommas",
"WithEqualsArray"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ func (t *Schema) arrayKeywords(tags []string) {

unprocessed := make([]string, 0, len(tags))
for _, tag := range tags {
nameValue := strings.Split(tag, "=")
nameValue := strings.SplitN(tag, "=", 2)
if len(nameValue) == 2 {
name, val := nameValue[0], nameValue[1]
switch name {
Expand Down
5 changes: 3 additions & 2 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ type Expression struct {
}

type PatternEqualsTest struct {
WithEquals string `jsonschema:"pattern=foo=bar"`
WithEqualsAndCommas string `jsonschema:"pattern=foo\\,=bar"`
WithEquals string `jsonschema:"pattern=foo=bar"`
WithEqualsAndCommas string `jsonschema:"pattern=foo\\,=bar"`
WithEqualsArray []string `jsonschema:"pattern=foo=bar"`
}

func TestReflector(t *testing.T) {
Expand Down