Skip to content
Merged
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
43 changes: 39 additions & 4 deletions src/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,47 @@ public function split(): \stdClass

public function validate(): bool
{
if ($this->openapi instanceof OA\OpenApi) {
return $this->openapi->validate();
if (!$this->openapi instanceof OA\OpenApi) {
$this->context->logger->warning('No openapi target set. Run the MergeIntoOpenApi processor before validate()');

return false;
}

$isValid = true;
$version = $this->openapi->openapi;
$context = new \stdClass();

foreach ($this->collectAnnotations($this->openapi) as $annotation) {
$isValid = $annotation->validate($this, $version, $context) && $isValid;
}

$this->context->logger->warning('No openapi target set. Run the MergeIntoOpenApi processor before validate()');
return $isValid;

}

/**
* @return array<OA\AbstractAnnotation>
*/
protected function collectAnnotations(OA\AbstractAnnotation $root): array
{
$annotations = [$root];

foreach (get_object_vars($root) as $field => $value) {
if (null === $value || Generator::isDefault($value) || is_scalar($value) || in_array($field, $root::$_blacklist)) {
continue;
}

return false;
if ($value instanceof OA\AbstractAnnotation) {
$annotations = array_merge($annotations, $this->collectAnnotations($value));
} elseif (is_array($value)) {
foreach ($value as $item) {
if ($item instanceof OA\AbstractAnnotation) {
$annotations = array_merge($annotations, $this->collectAnnotations($item));
}
}
}
}

return $annotations;
}
}
Loading