ex_json_schema icon indicating copy to clipboard operation
ex_json_schema copied to clipboard

Add config option for detailed message for nested errors

Open marmor157 opened this issue 3 years ago • 2 comments

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".

marmor157 avatar Jun 07 '22 15:06 marmor157

Coverage Status

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

coveralls avatar Jun 08 '22 09:06 coveralls

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?

jonasschmidt avatar Jun 20 '22 12:06 jonasschmidt