Skip to content

Commit

Permalink
Allow for = character in extra property values
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Novotney committed Nov 7, 2022
1 parent 55c890f commit fb292e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions fixtures/schema_with_expression.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema/expression",
"$ref": "#/$defs/Expression",
"$defs": {
"Expression": {
"properties": {
"value": {
"type": "integer",
"foo": "bar=='baz'"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"value"
]
}
}
}
2 changes: 1 addition & 1 deletion reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ func (t *Schema) arrayKeywords(tags []string) {

func (t *Schema) extraKeywords(tags []string) {
for _, tag := range tags {
nameValue := strings.Split(tag, "=")
nameValue := strings.SplitN(tag, "=", 2)
if len(nameValue) == 2 {
t.setExtra(nameValue[0], nameValue[1])
}
Expand Down
5 changes: 5 additions & 0 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ type KeyNamed struct {
RenamedByComputation int `jsonschema_description:"Description was preserved"`
}

type Expression struct {
Value int `json:"value" jsonschema_extras:"foo=bar=='baz'"`
}

func TestReflector(t *testing.T) {
r := new(Reflector)
s := "http://example.com/schema"
Expand Down Expand Up @@ -440,6 +444,7 @@ func TestSchemaGeneration(t *testing.T) {
}, "fixtures/keynamed.json"},
{MapType{}, &Reflector{}, "fixtures/map_type.json"},
{ArrayType{}, &Reflector{}, "fixtures/array_type.json"},
{Expression{}, &Reflector{}, "fixtures/schema_with_expression.json"},
}

for _, tt := range tests {
Expand Down

0 comments on commit fb292e4

Please sign in to comment.