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

Is the ReadMe upto date ? #24

Closed
praveen2710 opened this issue Mar 1, 2019 · 6 comments
Closed

Is the ReadMe upto date ? #24

praveen2710 opened this issue Mar 1, 2019 · 6 comments

Comments

@praveen2710
Copy link

I am using https://github.com/ruby-json-schema/json-schema as of now and as far as I can tell it not being maintained anymore. I was looking for similar feature but with better support and came across this one.

From what I can see in issue's it seems to be this gem can do a lot more than the Readme provides . Can the ReadMe be updated please ?

Things I want to know.
1)Is there a way to see errors on which there was a failure.examples in readMe would be great
2)Is there a way to customize the error message returned from json schema (ajv-errors)
3)Is there a way to fail on first validation issue vs make a list of all validation issue's (validate and fully_valdate in json shema)
4)Is there a way to access a portion of json schema (i.e my json data only consists on one property in json schema) eg: $ref = /path/to/json#properties/columns

I am new to this whole ruby gem community thing so apologies if I looked rude or something

@ahx
Copy link
Contributor

ahx commented Mar 1, 2019

@praveen2710 Me and a colleague just talked about 1):
schemer.validate({…}).to_a returns an array of Hashes that hold detailed information about what parts a failing. It's a bit hidden in the Readme, so here's another example:

schemer.validate({}).to_a
# =>
# [{"data"=>"string",
#   "data_pointer"=>"/0/id",
#   "root_schema"=>
#   {"items"=>
#     {"properties"=>
#       {"id"=>{"format"=>"int64", "type"=>"integer"},
#         "name"=>{"type"=>"string"},
#         "tag"=>{"type"=>"string"}},
#       "required"=>["id", "name"]},
#     "type"=>"array"},
#     "schema"=>{"format"=>"int64", "type"=>"integer"},
#     "schema_pointer"=>"/items/properties/id",
#     "type"=>"integer"}]

@gmac
Copy link

gmac commented Mar 7, 2019

@ahx – can you please be any more specific about how that translates into a meaningful error message? I'm validating a large data object with an equally large schema; the object is missing a required field, and what I get back is:

[{
  "data": { ... full data object ...},
  "data_pointer": "",
  "schema": { ... full schema object ... },
  "schema_pointer": "",
  "root_schema": { ... full schema object again? ... },
  "type": "required"
}]

Nowhere do I see any indication of what field is missing. I'm completely baffled by what to do with this result to turn it into anything useful to a human. Thanks for your insight.

@Draiken
Copy link
Contributor

Draiken commented Mar 7, 2019

This is definitely the biggest problem we've had with the gem too.
@gmac on your case, the pointer is blank, that means it's the root missing a field, but there's nothing that tells you which one(s).
Here

yield error(instance, 'required') if required && required.any? { |key| !data.key?(key) }
you can see it will return a required error if any key is missing, but the error has no reference to them.

I think I read somewhere that the author stopped refactoring that part waiting for the json schema RFC to define how to display errors, but the fact is, at this point it's very, very limited.

Maybe I'll submit a PR with some improvements if the author is ok with it.

@ahx
Copy link
Contributor

ahx commented Mar 8, 2019

You are right, I was hoping that the output would help understanding the error, but I don't understand how to parse it 😕

@davishmcclurg
Copy link
Owner

Hey y'all. Thanks for the interest.

There's an open issue for improving error messages: #1. I was waiting for the JSON Schema spec to document some output guidelines, which they did: json-schema-org/json-schema-spec#679. I worked on implementing them, but ran into some ambiguities that slowed me down. The current plan is to go with their "basic" output format, which is similar to what's already being generated. It doesn't really help the required case, so it's likely errors will need to be extended (like @Draiken did here: #25)

To answer your original question @praveen2710, the readme does not document all features. If you (or anyone else) is interested in working on docs, that would be great.

1)Is there a way to see errors on which there was a failure.examples in readMe would be great

JSONSchemer.schema(...).validate(...) returns an enumerator of errors, like @ahx described.

2)Is there a way to customize the error message returned from json schema (ajv-errors)

No

3)Is there a way to fail on first validation issue vs make a list of all validation issue's (validate and fully_valdate in json shema)

Yes, JSONSchemer.schema(...).valid?(...) returns false (and stops validating) if there's an error.

4)Is there a way to access a portion of json schema (i.e my json data only consists on one property in json schema) eg: $ref = /path/to/json#properties/columns

I'm not sure what you mean. Can you provide any more detail? You should be able to pass in any portion of you data.

@davishmcclurg
Copy link
Owner

I released some error improvements in 0.2.0. Thanks @Draiken!

Closing this. Feel free to ask more questions if you need clarification @praveen2710.

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

5 participants