Open ineu opened 8 years ago
That's an interesting point.
On Friday, 19 February 2016, Eugene Diachkin notifications@github.com wrote:
I have a following schema:
{ "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "foo" }, "description": { "type": "foo" }, "price": { "type": "foo" }, "created_at": { "type": "Fixnum" } } }
I expect
JSON::Validator.validate!(schema_path, json, strict: true, validate_schema: true)
to raise error saying something like 'type is unknown', unfortunately it doesn't. This way it's very easy to make a typo. I.e. I type 'Integer' instead of 'integer' and this property is just ignored.
— Reply to this email directly or view it on GitHub https://github.com/ruby-json-schema/json-schema/issues/309.
And the spec is pretty clear about this: Allowed are only the primitive types. So we have a bug/incomplete implementation.
That makes me think it should be in the common json schema test suite. I'll try to get it added
On Saturday, 20 February 2016, Jonas Peschla notifications@github.com wrote:
And the spec is pretty clear about this: Allowed are only the primitive types http://json-schema.org/latest/json-schema-validation.html#anchor79. So we have a bug/incomplete implementation.
— Reply to this email directly or view it on GitHub https://github.com/ruby-json-schema/json-schema/issues/309#issuecomment-186660267 .
I've thought about this some more, and this isn't something that should go into the common test suite at all. validate_schema: true
should raise an error as you originally suggested.
So I've just tried this, and it does raise an error:
JSON::Schema::ValidationError: The property '#/properties/name/type' of type <type of data> did not match one or more of the required schemas
Is that what you're seeing? So the issue is that the error message doesn't explain the cause of the problem?
@iainbeeston Not really. When I opened an issue, it just didn't raise exceptions. I can not reproduce it now, version 2.6.1 raises an exception as expected. Maybe it was my mistake.
But the error message is cryptic indeed. It would be great to paraphrase it to be about 'name', not about 'name/type'. 'Type' is a part of schema format, user is more interested in the property.
UPD: looks like the real issue is with $ref
pointing to invalid schemas. Trying to reproduce further
UPD2: So type defined in properties
in the json file is not validated if the file is included via $ref
I have a following schema:
I expect
to raise error saying something like 'type is unknown', unfortunately it doesn't. This way it's very easy to make a typo. I.e. I type 'Integer' instead of 'integer' and this property is just ignored.