From fb292e4c0ab70c80ac1ca8543d981cf2609947e2 Mon Sep 17 00:00:00 2001 From: Peter Novotney <> Date: Mon, 7 Nov 2022 15:31:41 -0800 Subject: [PATCH] Allow for = character in extra property values --- fixtures/schema_with_expression.json | 20 ++++++++++++++++++++ reflect.go | 2 +- reflect_test.go | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 fixtures/schema_with_expression.json diff --git a/fixtures/schema_with_expression.json b/fixtures/schema_with_expression.json new file mode 100644 index 0000000..dcdb2e1 --- /dev/null +++ b/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" + ] + } + } + } \ No newline at end of file diff --git a/reflect.go b/reflect.go index 0592525..4876ec2 100644 --- a/reflect.go +++ b/reflect.go @@ -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]) } diff --git a/reflect_test.go b/reflect_test.go index 5de45e9..6bc2e1f 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -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" @@ -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 {