diff --git a/fixtures/allow_additional_props.json b/fixtures/allow_additional_props.json index 20d58fb..a2fe8d1 100644 --- a/fixtures/allow_additional_props.json +++ b/fixtures/allow_additional_props.json @@ -140,6 +140,11 @@ ], "hello": "world" }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, "color": { "type": "string", "enum": [ diff --git a/fixtures/defaults_expanded_toplevel.json b/fixtures/defaults_expanded_toplevel.json index ca43057..c57ca8f 100644 --- a/fixtures/defaults_expanded_toplevel.json +++ b/fixtures/defaults_expanded_toplevel.json @@ -140,6 +140,11 @@ ], "hello": "world" }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, "color": { "type": "string", "enum": [ diff --git a/fixtures/ignore_type.json b/fixtures/ignore_type.json index 383e7ab..2a08af6 100644 --- a/fixtures/ignore_type.json +++ b/fixtures/ignore_type.json @@ -134,6 +134,11 @@ ], "hello": "world" }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, "color": { "type": "string", "enum": [ diff --git a/fixtures/no_reference.json b/fixtures/no_reference.json index 67b2e19..abbe6ec 100644 --- a/fixtures/no_reference.json +++ b/fixtures/no_reference.json @@ -129,6 +129,11 @@ ], "hello": "world" }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, "color": { "type": "string", "enum": [ diff --git a/fixtures/no_reference_anchor.json b/fixtures/no_reference_anchor.json index a6a6e42..154c5b2 100644 --- a/fixtures/no_reference_anchor.json +++ b/fixtures/no_reference_anchor.json @@ -131,6 +131,11 @@ ], "hello": "world" }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, "color": { "type": "string", "enum": [ diff --git a/fixtures/required_from_jsontags.json b/fixtures/required_from_jsontags.json index af71f1d..3a41aaa 100644 --- a/fixtures/required_from_jsontags.json +++ b/fixtures/required_from_jsontags.json @@ -141,6 +141,11 @@ ], "hello": "world" }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, "color": { "type": "string", "enum": [ diff --git a/fixtures/test_user.json b/fixtures/test_user.json index 43ad542..8ef1d01 100644 --- a/fixtures/test_user.json +++ b/fixtures/test_user.json @@ -141,6 +141,11 @@ ], "hello": "world" }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, "color": { "type": "string", "enum": [ diff --git a/fixtures/test_user_assign_anchor.json b/fixtures/test_user_assign_anchor.json index 8031188..c5e6198 100644 --- a/fixtures/test_user_assign_anchor.json +++ b/fixtures/test_user_assign_anchor.json @@ -143,6 +143,11 @@ ], "hello": "world" }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, "color": { "type": "string", "enum": [ diff --git a/reflect.go b/reflect.go index 1b6732d..36ee30a 100644 --- a/reflect.go +++ b/reflect.go @@ -874,13 +874,23 @@ func (t *Schema) setExtra(key, val string) { t.Extras[key] = append(existingVal, val) case int: t.Extras[key], _ = strconv.Atoi(val) + case bool: + t.Extras[key] = (val == "true" || val == "t") } } else { switch key { case "minimum": t.Extras[key], _ = strconv.Atoi(val) default: - t.Extras[key] = val + var x interface{} + if val == "true" { + x = true + } else if val == "false" { + x = false + } else { + x = val + } + t.Extras[key] = x } } } diff --git a/reflect_test.go b/reflect_test.go index f02a71a..72e6922 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -95,7 +95,8 @@ type TestUser struct { UUID string `json:"uuid" jsonschema:"format=uuid"` // Test for "extras" support - Baz string `jsonschema_extras:"foo=bar,hello=world,foo=bar1"` + Baz string `jsonschema_extras:"foo=bar,hello=world,foo=bar1"` + BoolExtra string `json:"bool_extra,omitempty" jsonschema_extras:"isTrue=true,isFalse=false"` // Tests for simple enum tags Color string `json:"color" jsonschema:"enum=red,enum=green,enum=blue"`