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

Allow for = character in custom property fields #57

Merged
merged 1 commit into from Nov 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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