-
Notifications
You must be signed in to change notification settings - Fork 354
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
Custom error message #239
Comments
I haven't checked how you implement custom error messages, but the approach described in this issue comment seems like a rather nice one: geraintluff/tv4#115 (comment) |
+1 |
The error message you mentioned above is still in the code base but has shifted a bit. For reference you can find them here: @csimplestring Since your issue report the repo has progressed and since #364 the property became available. Using below example code you can see the property is now part of the errors. Schema: {
"type": "object",
"additionalProperties": false
} Code: <?php
use JsonSchema\Constraints\Constraint;
use JsonSchema\Uri\UriRetriever;
use JsonSchema\Validator;
require_once '../../vendor/autoload.php';
$retriever = new UriRetriever();
$schema = $retriever->retrieve('internal://' . realpath('./schema.json'));
$obj = json_decode('{"foo": "bar"}', false);
$validator = new Validator();
$result = $validator->validate($obj, $schema, Constraint::CHECK_MODE_APPLY_DEFAULTS);
var_dump($validator->getErrors()[0]["constraint"]["params"]["property"]); Output: string(3) "foo" |
Hi, it is great to support customized error message in the 1.6.0 release. But after reading the source code for a while, I notice a minor issue during adding error:
$this->addError($path, 'The item ' . $i . '[' . $k . '] is not defined and the definition does not allow additional items', 'additionalItems', array('additionalItems' => $schema->additionalItems,));
The problem is that the 'not-allowed' field '$i' and '$k' is in the error message, external users have to parse it from error message. Once the error message is changed, external users have to change parsing accordingly.
Therefore to fully support customized error message, the error message should not contain any error field path, e.g., '$i', '$k', which shall be moved to '$path' instead.
The text was updated successfully, but these errors were encountered: