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

display violation elements #578

Open
thawkins opened this issue Jul 23, 2019 · 5 comments
Open

display violation elements #578

thawkins opened this issue Jul 23, 2019 · 5 comments

Comments

@thawkins
Copy link

I would like to propose having the error logging on the constraints checkers optionaly store a value called "element" that shows the actual value that failed the constraint, this would be valuable in understanding the violations. this could be linked to a constraints::[option] to turn it on and off.

for example

changing line 52 in the enumconstraints.php from

$this->addError($path, 'Does not have a value in the enumeration ' . json_encode($schema->enum), 'enum', array('enum' => $schema->enum));

to:

$this->addError($path, 'Does not have a value in the enumeration ' . json_encode($schema->enum), 'enum', array('enum' => $schema->enum, 'element'=>$element)); 

would meet this requirement, i'm sure there are lots of other places in the other constraints checkers where this would make sense.

There is one hazard, if the $element is itself the root of a large subtree it could bloat things on the output, in particular if the violation is detected on the root of the document being validated. requiredConstraint already displays the name of the violating element as does many other constraint checkers.

@erayd
Copy link
Contributor

erayd commented Jul 23, 2019

We already provide an explicit path / pointer to the failing element, so that users may refer directly to the value within the source document. Can you expand on why that isn't sufficient?

@thawkins
Copy link
Author

You have to dig into tbe document to find the issue in the structure if you only have the path, particularly with enums its useful to show what the actual value that failed the constraint check is, its make it easier to determine what the failing item is.

I have been working on validating a 2000 line schema against a set of mongodb records, we wrote an etl to work througb all the records in a collection and run the validator against each, storing the violations and the record id in another collection. Having tbe violating element in the output makes interpretting that data much easier.

Its not a big deal, i can hack the package for our use, but it woukd have been easer for me to have it in the distribution.

@erayd
Copy link
Contributor

erayd commented Jul 24, 2019

@thawkins I'm open to having it included, provided it doesn't impact performance and doesn't introduce needless complexity.

@shmax What do you think?

@shmax
Copy link
Collaborator

shmax commented Jul 24, 2019

No objections.

@erayd
Copy link
Contributor

erayd commented Jul 24, 2019

@thawkins In light of the discussion above, please feel free to submit a PR that implements this, and we will look to getting it merged in to the v6 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants