Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/Keywords/AllOfKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio
{
$object = $this->createArrayObject($context);

$errors = [];

foreach ($this->value as $index => $value) {
if ($value === true) {
continue;
}

if ($value === false) {
$this->addEvaluatedFromArrayObject($object, $context);
return $this->error($schema, $context, 'allOf', 'The data should match all schemas', [
$error = $this->error($schema, $context, 'allOf', 'The data should match all schemas', [
'index' => $index,
]);
if ($context->stopAtFirstError()) {
return $error;
}
$errors[] = $error;
}

if (is_object($value) && !($value instanceof Schema)) {
Expand All @@ -65,14 +71,24 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio

if ($error = $context->validateSchemaWithoutEvaluated($value, null, false, $object)) {
$this->addEvaluatedFromArrayObject($object, $context);
return $this->error($schema, $context, 'allOf', 'The data should match all schemas', [
$error = $this->error($schema, $context, 'allOf', 'The data should match all schemas', [
'index' => $index,
], $error);
if ($context->stopAtFirstError()) {
return $error;
}
$errors[] = $error;
}
}

if (count($errors) > 0 && !$context->stopAtFirstError()) {
return $this->error($schema, $context, 'allOf', 'The data should match all schemas', [
'index' => $index,
], $errors);
}

$this->addEvaluatedFromArrayObject($object, $context);

return null;
}
}
}
33 changes: 27 additions & 6 deletions src/Schemas/ObjectSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,50 @@ public function validate(ValidationContext $context): ?ValidationError
*/
public function doValidate(ValidationContext $context): ?ValidationError
{
$errors = [];
if ($this->before && ($error = $this->applyKeywords($this->before, $context))) {
return $error;
if ($context->stopAtFirstError()) {
return $error;
}
$errors[] = $error;
}

if ($this->types && ($type = $context->currentDataType())) {
if (isset($this->types[$type]) && ($error = $this->applyKeywords($this->types[$type], $context))) {
return $error;
if ($context->stopAtFirstError()) {
return $error;
}
$errors[] = $error;
}

if (($type = Helper::getJsonSuperType($type)) && isset($this->types[$type])) {
if ($error = $this->applyKeywords($this->types[$type], $context)) {
return $error;
if ($context->stopAtFirstError()) {
return $error;
}
$errors[] = $error;
}
}

unset($type);
}

if ($this->after && ($error = $this->applyKeywords($this->after, $context))) {
return $error;
if ($context->stopAtFirstError()) {
return $error;
}
$errors[] = $error;
}

if (count($errors) === 0) {
return null;
}

if (count($errors) === 1) {
return $errors[0];
}

return null;
return new ValidationError('', $this, DataInfo::fromContext($context), 'Data must match schema', [], $errors);
}

/**
Expand Down Expand Up @@ -145,4 +166,4 @@ protected function applyKeywords(array $keywords, ValidationContext $context): ?
$error_list
);
}
}
}