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

Made validation sub errors indicate where they come from #138

Merged
merged 3 commits into from
Oct 26, 2014

Conversation

iainbeeston
Copy link
Contributor

When using anyof or allof in a schema, all of the validation errors for
all of the subschemas are shown in a flat list - all concatenated
together. This makes it very hard (or impossible) to see where in the
schema individual errors come from, and makes it hard to debug the
errors in your json.

This change groups subschema errors together, according to which schema
they appeared under.

I've been testing this on a schema that has an anyOf validation with 6 possible sub schemas. For that the error messages now appear like:

The property '#/0' of type Hash did not match one or more of the required schemas. The schema specific errors were:

- subschema #0:
    - The property '#/0' did not contain a required property of 'text'
    - The property '#/0/type' value "basic_question" did not match one of the following values: text
    - The property '#/0' contains additional properties ["title", "required", "number", "identifier"] outside of the schema when none are allowed
- subschema #1:
    - The property '#/0/type' value "basic_question" did not match one of the following values: section, subsection
    - The property '#/0' contains additional properties ["required", "number", "identifier"] outside of the schema when none are allowed
- subschema #2:
    - The property '#/0' did not contain a required property of 'subtitle'
    - The property '#/0/type' value "basic_question" did not match one of the following values: repeatable_section
    - The property '#/0' contains additional properties ["required", "number", "identifier"] outside of the schema when none are allowed
- subschema #3:
    - The property '#/0' contains additional properties ["number", "identifier"] outside of the schema when none are allowed
- subschema #4:
    - The property '#/0/type' value "basic_question" did not match one of the following values: grouped_question, multi_grouped_question, question_table
    - The property '#/0' contains additional properties ["number", "identifier"] outside of the schema when none are allowed
- subschema #5:
    - The property '#/0/type' value "basic_question" did not match one of the following values: grouped_question, multi_grouped_question, question_table
    - The property '#/0' contains additional properties ["number", "identifier"] outside of the schema when none are allowed

Where before you'd see this:

The property '#/0' of type Hash did not match one or more of the required schemas in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 The schema specific errors were:
 - The property '#/0' did not contain a required property of 'text' in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0/type' value "basic_question" did not match one of the following values: text in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0' contains additional properties ["title", "required", "number", "identifier"] outside of the schema when none are allowed in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0/type' value "basic_question" did not match one of the following values: section, subsection in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0' contains additional properties ["required", "number", "identifier"] outside of the schema when none are allowed in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0' did not contain a required property of 'subtitle' in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0/type' value "basic_question" did not match one of the following values: repeatable_section in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0' contains additional properties ["required", "number", "identifier"] outside of the schema when none are allowed in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0' contains additional properties ["number", "identifier"] outside of the schema when none are allowed in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0/type' value "basic_question" did not match one of the following values: grouped_question, multi_grouped_question, question_table in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0' contains additional properties ["number", "identifier"] outside of the schema when none are allowed in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0/type' value "basic_question" did not match one of the following values: grouped_question, multi_grouped_question, question_table in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#
 - The property '#/0' contains additional properties ["number", "identifier"] outside of the schema when none are allowed in schema 9daf715e-c908-5089-96eb-cd2aa57b05cf#

When using anyof or allof in a schema, all of the validation errors for
all of the subschemas are shown in a flat list - all concatenated
together. This makes it very hard (or impossible) to see where in the
schema individual errors come from, and makes it hard to debug the
errors in your json.

This change groups subschema errors together, according to which schema
they appeared under.
Feels more general, and easier to understand
@pd
Copy link
Contributor

pd commented Oct 25, 2014

👍 -- this seems to be working well on schemas I use to validate an API I work on!

@hoxworth
Copy link
Contributor

👍 This is great!

hoxworth added a commit that referenced this pull request Oct 26, 2014
Made validation sub errors indicate where they come from
@hoxworth hoxworth merged commit a5348d5 into voxpupuli:master Oct 26, 2014
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