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

Add config option for detailed message for nested errors #77

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

marmor157
Copy link

@marmor157 marmor157 commented Jun 7, 2022

This PR adds ability to set detailed_errors feature flag in config.

Setting this enables detailed error output for errors that can contain other errors inside, e.g. AllOf, AnyOf

Example detailed message for AllOf with nested AnyOf looks like this:

Expected all of the schemata to match, but the schemata at the following indexes did not: 1.

The following errors were found:
  1: Expected any of the schemata to match but none did.
  
  The following errors were found:
    0: Expected data to be "1".
    1: Expected data to be "2".
    2: Expected data to be "3".
    3: Expected data to be "4".
    4: Expected data to be "5".
    5: Expected data to be "6".

@coveralls
Copy link

coveralls commented Jun 8, 2022

Coverage Status

Coverage decreased (-5.3%) to 89.636% when pulling 396307d on marmor157:master into a1191fc on jonasschmidt:master.

@jonasschmidt
Copy link
Owner

I think it might be a bit "cleaner" to be able to specify an options keyword list for the error formatter, like so: ExJsonSchema.Validator.validate(schema, %{"foo" => 1}, error_formatter: {ExJsonSchema.Validator.Error.StringFormatter, nested_errors?: true}). That options list could then be passed through to ExJsonSchema.Validator.Error.StringFormatter.format/1. Doesn't seem quite right to have the error formatter be an option in the validate call but the way it operates is defined via a global config. What do you think?

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

Successfully merging this pull request may close these issues.

3 participants