pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
466 stars 134 forks source link

Optional error reporting for logical combinations #105

Closed ghost closed 3 months ago

ghost commented 4 years ago

Hello,

In current version class logical_combination reports generic error after evaluation of all variants of subschema. It would be nice to add an option to log errors from individual subschemas as well if overall validation fails.

pboettch commented 4 years ago

This was existing in the first version of the library, which was otherwise so much worse.

The problem is that with the error message callback you'd get message of failing combination-items which would be difficult to understand.

And I assume furthermore you would not want the error messages of failing combination-items if another one would be successful. So we would need to filter.

I might try something.

pboettch commented 3 years ago

I tried something and I have it on a local branch. Note to myself.

gabor-varga commented 3 years ago

Hi @pboettch , did you ever revisit this issue on your local branch?

pboettch commented 3 years ago

@gabor-varga Yes I still have it on local. Would you mind testing and using it to see whether it fills the needs? I have to say it's quite verbose and only human readable.

pboettch commented 3 years ago

I pushed an 'error-check'-branch which contains a change printing sub-schema errors if the logical-combination has failed.

gabor-varga commented 3 years ago

Thanks @pboettch , I will check it. I basically want to find a way to print meaningful error messages on validation error that lets the user debug their config. We have quite complex schemas with many one_of.

ghost commented 3 years ago

Thank you @pboettch , I will try to use and test it as well.

iksemyonov commented 2 years ago

Hi @pboettch, have there been there any updates on the issue since January? Have you considered merging the branch to master? Also, with my github account, I can't find the branch called error-check, has it been deleted since, or is it private?

pboettch commented 2 years ago

It seems I forgot to push it.

pboettch commented 2 years ago

Done.

pboettch commented 2 years ago

https://github.com/pboettch/json-schema-validator/tree/error-check

lpelerin commented 1 year ago

Hi @pboettch, I've tested a bit your error-check branch and found it quite useful. Do you plan on merging this to master?

zecoaat commented 5 months ago

Hi @pboettch,

I also checked the error-check branch, but the solution is not exactly what we were looking for.

I've found two issues:

I have a proposal for fixing these issues and have all of the logical combination error messages: https://github.com/zecoaat/json-schema-validator

For the default error handler it works like earlier - only the root logical combination error will be thrown.

However, if you install a custom error handler, you can get all the details about the various cases:

no subschema has succeeded, but one of them is required to validate. Type: anyOf, number of failed subschemas: 3
[combination: anyOf / case#0] no subschema has succeeded, but one of them is required to validate. Type: anyOf, number of failed subschemas: 2
[combination: anyOf / case#0] [combination: anyOf / case#0] instance is below minimum of 5
[combination: anyOf / case#0] [combination: anyOf / case#1] instance is not a multiple of 2.0
[combination: anyOf / case#1] unexpected instance type
[combination: anyOf / case#2] unexpected instance type

(You can find the schema used for this test in the fork-project in tests.)

Please review the changes and consider merging this fork into the upstream project. Thank you in advance, Jimmy

pboettch commented 4 months ago

@zecoaat Do not hesite to make a pull-request here! Your work's output looks nice.

zecoaat commented 4 months ago

@pboettch I created the pull request for the modifications: https://github.com/pboettch/json-schema-validator/pull/310

pboettch commented 3 months ago

Fixed with #310. Thanks @zecoaat .