-
Notifications
You must be signed in to change notification settings - Fork 57
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
Validation stops on first error #107
Comments
For our project we are depending on this. (Not on the suggested error limits, though.) We'd like to avoid a custom fork so we would highly appreciate if a solution for this issue can be found. Ping @sorinsarca :-) |
This code in protected function applyKeywords(array $keywords, ValidationContext $context): ?ValidationError
{
$errors = [];
foreach ($keywords as $keyword) {
if (null !== ($error = $keyword->validate($context, $this))) {
$errors[] = $error;
}
}
if ([] === $errors) {
return null;
}
if (1 === \count($errors)) {
return $errors[0];
}
/** @var Schema $schema */
$schema = $context->schema();
return new ValidationError(
'schema',
$schema,
DataInfo::fromContext($context),
'The data does not match the schema',
['data' => $context->currentData()],
$errors
);
} The part if (1 === \count($errors)) {
return $errors[0];
} isn't necessary, though if there's only one error the behavior is as before. Edit: Changed error message to not contain json-schema/src/Errors/ErrorFormatter.php Line 231 in c48df6d
(Showing the whole JSON in the error message probably makes no sense in most cases...) |
I agree with @dontub. Tried code and works as a breeze! :D |
We have tried using the fork from @orakili and the code resolves the mentioned issue. It would be also highly appreciated if the fix get merged to master so we can also avoid using forks! :) |
Or this document may solve your problem? https://opis.io/json-schema/2.x/php-validator.html#max-errors |
We have actually set the max Errors to 100 in this case :( so I don't think that will have an impact. But I will give it a try with a lower number such as 5. Edit: I just tried it with a lower number and the behaviour is still the unwanted one. |
Currently the validation stops if an error occurs.
json-schema/src/Schemas/ObjectSchema.php
Line 114 in c48df6d
So if for example a required property is missing, the available properties are not validated at all. Actually we need to have all object properties/array items to be validated.
Maybe it would make sense to have different maximum error limits:
type
is number, but a string is given. Then it makes sense to stop the validation for this data without checking further keywords likeminimum
.)The text was updated successfully, but these errors were encountered: