Skip to content

Commit

Permalink
Merge pull request #57 from PeterNovotney/allow-equals
Browse files Browse the repository at this point in the history
Allow for = character in custom property fields
  • Loading branch information
samlown committed Nov 8, 2022
2 parents 55c890f + fb292e4 commit a7e9715
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
@@ -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
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
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 a7e9715

Please sign in to comment.