-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add "schemaPath" to verbose output, showing which subschema triggered each error. #148
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I'll give @mafintosh a few days to look, otherwise I'll merge it 👍 Feel free to ping me if (when) I forget 😄 |
@LinusU: Thanks for looking at it so quickly! I wasn't quite finished :p I've added some tests, fixed a bug they turned up, updated the docs and squashed, so I think I'm done now :) I've just realized that squashing is going to make it harder for you to see the changes :( The only semantic difference is the bugfix, where I added added a check for I did also have a look at #38 and #22 which both talked about something like this, but I don't think it fits here. When I'm a fan of the the feature those issues describe, and I'd be keen to see it implemented in some form, I'm just saying that I don't think it fits into the path. |
e93f9d6
to
1d8334c
Compare
README.md
Outdated
verbose: true | ||
}) | ||
|
||
validate({hello: 100}); | ||
console.log(validate.errors) // {field: 'data.hello', message: 'is the wrong type', value: 100, type: 'string'} | ||
console.log(validate.errors, null, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing that null, 2
was intended for a JSON.stringfy call and not a console.log one :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, thanks :) Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small nit 👍
No problem at all 👌
👍 |
1d8334c
to
1edfc55
Compare
I know that feeling so well. Ping :) |
Published as 2.17.0 🚀 Thank you for your contribution! |
node 5.12.0, same error: |
Shit, working on this! |
If anyone could give me a stacktrace I would appreciate it! |
Yeah, just say 😄 Fix published as |
Me too, Sorry! :'( I feel pretty stupid about it having seen the fix - I added a bunch of tests but not the right ones :( Breaking downstream packages is a first for me, and I'd love to never do it again - is there something I could/should have done to catch this ahead of time? |
Don't beat yourself up, I missed it too!
Not really, we should definitely look at getting code coverage up and running though, and I would love to migrate to TypeScript which would have caught this error as well. Other than that it's just trying to add as many tests as possible 😄 |
This PR adds a 'schemaPath' to the verbose output that can be used to get back to the failed rule in the schema in order to associate metadata with failures.
This provides a solution to #102 and #122 by making it possible to pull the appropriate
additionalProperties
orenum
out of the schema.For example, given this schema:
You can validate trace back failures to the
and this test program:
We can get the correct rule and it's metadata back out of the schema:
The patch adds only the extra static string to the generated validation functions, so it should have virtually no effect on performance. (There's a very modest amount of extra work being done at compile time).
I added paths for
anyOf
andoneOf
, but then I pulled it out again. I think it doesn't make sense to dive into them.I've added paths to every call to visit, but I haven't exercised any of it, so they're probably wrong right now and need some tests.