Closed bparanj closed 9 years ago
No this is the expected result. When you pass "42" to JSON-Schema, it sees that it is a string and assumes that it's a JSON text which needs parsing. So it passes it to the JSON gem. That parses it as the number 42, which is valid in your schema.
To get the behaviour you expect you need to pass a JSON text containing the string "42" (eg data = '"42"'). Or you can tell json-schema that the string does not need parsing, by calling validate(schema, data, json: true) - this will try to validate the string "42"
Thanks for the response. You can close it.
According to this document: http://spacetelescope.github.io/understanding-json-schema/UnderstandingJSONSchema.pdf
type : 'number' should fail if the data is a string but it does not. Here is a spec to reproduce the problem: