prolab-api/vendor/zircote/swagger-php/src/Processors/MergeIntoComponents.php

37 lines
1002 B
PHP
Raw Normal View History

2025-09-24 06:24:52 +00:00
<?php declare(strict_types=1);
/**
* @license Apache 2.0
*/
namespace OpenApi\Processors;
use OpenApi\Analysis;
2025-10-04 09:16:19 +00:00
use OpenApi\Annotations\Components;
2025-09-24 06:24:52 +00:00
use OpenApi\Context;
use OpenApi\Generator;
/**
* Merge reusable annotation into @OA\Schemas.
*/
2025-10-04 09:16:19 +00:00
class MergeIntoComponents
2025-09-24 06:24:52 +00:00
{
public function __invoke(Analysis $analysis)
{
$components = $analysis->openapi->components;
2025-10-04 09:16:19 +00:00
if ($components === Generator::UNDEFINED) {
$context = new Context([], $analysis->context);
$components = new Components(['_context' => $context]);
$components->_context->generated = true;
2025-09-24 06:24:52 +00:00
}
foreach ($analysis->annotations as $annotation) {
2025-10-04 09:16:19 +00:00
if (Components::matchNested(get_class($annotation)) && $annotation->_context->is('nested') === false) {
2025-09-24 06:24:52 +00:00
// A top level annotation.
$components->merge([$annotation], true);
$analysis->openapi->components = $components;
}
}
}
}