opis / json-schema

JSON Schema validator for PHP
https://opis.io/json-schema
Apache License 2.0
567 stars 58 forks source link

[Question] Is there a way to generate error output? #105

Open JeroenDeDauw opened 2 years ago

JeroenDeDauw commented 2 years ago

I am aware that the ValidationResult returned by validate() can contain a ValidationError.

Does this library provide a way to turn a ValidationError into an error text that can be shown to the user? Looks like generating such a message is somewhat involved, with ValidationError containing multiple potentially relevant fields, including subErrors. So I rather not reinvent the wheel here.

For my use cases this message does not need to be fancy or particularly user friendly. Something akin to a stack trace would work great and is miles better than just dumping a serialized version of ValidationError.

JeroenDeDauw commented 2 years ago

Something similar to https://www.php.net/manual/en/throwable.gettraceasstring.php

sorinsarca commented 2 years ago

https://opis.io/json-schema/2.x/php-error-formatter.html