- don't panic if a string's patter isn't a string.
diff --git a/schema_test.go b/schema_test.go
index 5306ea1..80fa747 100644
--- a/schema_test.go
+++ b/schema_test.go
@@ -495,3 +495,22 @@
t.Errorf("Got error: %s", err.Error())
}
}
+
+const invalidPattern = `{
+ "title": "Example Pattern",
+ "type": "object",
+ "properties": {
+ "invalid": {
+ "type": "string",
+ "pattern": 99999
+ }
+ }
+}`
+
+func TestInvalidPattern(t *testing.T) {
+ loader := NewStringLoader(invalidPattern)
+ _, err := NewSchema(loader)
+ if err == nil {
+ t.Errorf("Expected error for invalid pattern type: %s", err.Error())
+ }
+}
diff --git a/utils.go b/utils.go
index 4cbe0dc..26cf75e 100644
--- a/utils.go
+++ b/utils.go
@@ -34,7 +34,12 @@
)
func isKind(what interface{}, kind reflect.Kind) bool {
- return reflect.ValueOf(what).Kind() == kind
+ target := what
+ if isJsonNumber(what) {
+ // JSON Numbers are strings!
+ target = *mustBeNumber(what)
+ }
+ return reflect.ValueOf(target).Kind() == kind
}
func existsMapKey(m map[string]interface{}, k string) bool {