ruby-jsonchema icon indicating copy to clipboard operation
ruby-jsonchema copied to clipboard

Cannot self-validate the schema

Open TelegramSam opened this issue 14 years ago • 7 comments

The spec says that the schema is self validating, but when I try using your library, I get this error:

    JSON::Schema::ValueError: dependencies is missing and it is not optional

    /Library/Ruby/Gems/1.8/gems/jsonschema-2.0.0/lib/jsonschema.rb:40:in `check_property'
    /Library/Ruby/Gems/1.8/gems/jsonschema-2.0.0/lib/jsonschema.rb:209:in `check_object'
    /Library/Ruby/Gems/1.8/gems/jsonschema-2.0.0/lib/jsonschema.rb:207:in `each'
    /Library/Ruby/Gems/1.8/gems/jsonschema-2.0.0/lib/jsonschema.rb:207:in `check_object'
    /Library/Ruby/Gems/1.8/gems/jsonschema-2.0.0/lib/jsonschema.rb:99:in `check_property'
    /Library/Ruby/Gems/1.8/gems/jsonschema-2.0.0/lib/jsonschema.rb:287:in `validate'
    /Library/Ruby/Gems/1.8/gems/jsonschema-2.0.0/lib/jsonschema.rb:298:in `validate'
    ./sqapp.rb:96:in `POST /d/schemas/add'

TelegramSam avatar Feb 14 '11 18:02 TelegramSam

This library is in accordance with JSON Schema 2nd Draft ( http://groups.google.com/group/json-schema/web/json-schema-proposal---second-draft ), excepting Extending and Referencing / unique property.

Thanks for your report.

Constellation avatar Feb 26 '11 09:02 Constellation

Are you planning to update to draft 3, which replaces the "optional" attribute with "required" attribute (and makes optional the default)?

jfirebaugh avatar Mar 21 '11 21:03 jfirebaugh

I would like to implement draft 3 JSON Schema in the future. but, JSON Schema draft 3 is very complexed (such as format, URI based $schema, etc.), so this takes a little long time...

thx.

Constellation avatar Apr 29 '11 11:04 Constellation

If interested, I have a fairly stable draft-3 compliant Ruby json schema validator at https://github.com/hoxworth/json-schema. The validator also supports draft-1 and draft-2, and will be tracking any future updates to the JSON Schema spec.

hoxworth avatar Apr 29 '11 14:04 hoxworth

Oh! Thanks!!! Your implementation is great!

Do you think about the 3rd draft complicated attributes like "regexp" in "format", "$ref" with the external URL(http://...)?

Constellation avatar Jun 14 '11 21:06 Constellation

The $ref attribute is definitely handled and resolves against absolute and relative URIs. The library will load external 'http' and 'file' URI schemes if the URI is not explicitly defined in the schema, and will treat all other URIs as internal references.

As for format, the library does not explicitly enforce that the instance value matches the constraints of a format. The draft spec explicitly states that validators are not required to enforce these rules and that the 'format' attribute is to be used mostly as an inference tool by consumers of data that adhere to a JSON schema.

There are probably a few more things that need to be ironed out in this library; however it is pretty simple to add / remove features and declare new schemas. I will be moving the library into its first major release once the JSON schema is finalized past the draft stage and proper testing has been performed.

hoxworth avatar Jun 15 '11 15:06 hoxworth

Oh thanks!

The draft spec explicitly states that validators are not required to enforce these rules and that the 'format' attribute is to be used mostly as an inference tool by consumers of data that adhere to a JSON schema.

Oh! I overlooked. I misunderstood that JSON Schema spec requires completely implementation of "format".

Constellation avatar Jul 02 '11 06:07 Constellation