Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors for required properties do not contain the fragment correctly. #115

Closed
yorickpeterse opened this issue Aug 12, 2014 · 6 comments
Closed

Comments

@yorickpeterse
Copy link

Assume we have the following script (based on the documentation in the README):

require 'json-schema'

schema = {
  "type" => "object",
  "required" => ["a"],
  "properties" => {
    "a" => {"type" => "integer"}
  }
}

data = {}

JSON::Validator.validate!(schema, data)

Running this results in the following output:

The property '#/' did not contain a required property of 'a' in schema 221df103-b050-5d5c-8ee8-aa1d185ac383# (JSON::Schema::ValidationError)

This error message doesn't seem to include the fragment for the "a" property correctly. If we specify an incorrect type on the other hand it is set properly:

require 'json-schema'

schema = {
  "type" => "object",
  "required" => ["a"],
  "properties" => {
    "a" => {"type" => "integer"}
  }
}

data = {'a' => 'foo'}

JSON::Validator.validate!(schema, data)

Which results in:

The property '#/a' of type String did not match the following type: integer in schema 221df103-b050-5d5c-8ee8-aa1d185ac383# (JSON::Schema::ValidationError)
@pd
Copy link
Contributor

pd commented Aug 12, 2014

The error message seems correct to me; it is stating that the object at #/ was expected to have a property a, but doesn't. If the fragment were to be #/a, I would read that as an expectation that #/a/a existed.

@yorickpeterse
Copy link
Author

@pd Hm good point, but in that case this could be clarified by using a better error message. The current error message is far too cryptic.

@anicholson
Copy link

👍 @pd - the error messages are what I would expect to see. @yorickpeterse, how would you make them better? :)

@hoxworth
Copy link
Contributor

I am definitely open to suggestions on improving the wording of the error text, but I am unsure that this particular message needs more clarity. I would be happy to hear suggestions, but I am going to close this issue as it is not a code defect. Please feel free to continue the discussion!

@anicholson
Copy link

The only way I can think of making the error message more informative would be to display the part of the schema that fails the validation - but that would be a fair bit of effort, I think.

@yorickpeterse
Copy link
Author

Something along the lines of the following is at least less confusing: The property '#/a' is required in schema .... Reading the current error message provides little help with figuring out what field(s) you actually need to add to pass validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants