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

jsonschema needs a method to report *all* errors in an instance #15

Closed
b5 opened this issue Jan 19, 2018 · 1 comment · Fixed by #22
Closed

jsonschema needs a method to report *all* errors in an instance #15

b5 opened this issue Jan 19, 2018 · 1 comment · Fixed by #22
Assignees

Comments

@b5
Copy link
Member

b5 commented Jan 19, 2018

currently we only have one usable Method for Validation:

jsonschema.RootSchema.ValidateBytes(data []byte) error

That bails on the first error it sees.

We need a method that collects all known errors in a slice of bytes. I'm thinking it's signature should look like this:

jsonschema.RootSchema.Errors(data []byte) ([]string, error)

the slice of string should be the result of appending err.Error() to the result anytime err != nil in the validation stack. the function should only return error != nil if the data won't parse.

@handrews
Copy link

You may be interested in json-schema-org/json-schema-spec#396 related to this, about a possible suggested error output format.

b5 added a commit that referenced this issue Jan 20, 2018
This commit introduces a new type: ValError and adjusts the
signature of Validator.Validate to return a slice of ValError
instead of a single error. This change comes with the expectation
that all validators should return the full list of errors that
a given validator detects. Error-free passes can return either
nil or an empty []ValError slice.
This adjustment starts with a basic "just supply the message",
but ValError comes with extra fields that we can iterate upon
to populate in the future.
Having the full list of errors for a given instance makes this
package far more useful, at the expense of forcing implementers
to understand a few extra things. Meh. Worth it.

closes #15
@ghost ghost assigned b5 Jan 20, 2018
@ghost ghost added the in progress label Jan 20, 2018
@b5 b5 closed this as completed in #22 Jan 22, 2018
@ghost ghost removed the in progress label Jan 22, 2018
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 a pull request may close this issue.

2 participants