| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
/** |
| 4 |
* @license Apache 2.0 |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace OpenApi\Processors; |
| 8 |
|
| 9 |
use OpenApi\Analysis; |
| 10 |
use OpenApi\Annotations as OA; |
| 11 |
use OpenApi\Generator; |
| 12 |
|
| 13 |
/** |
| 14 |
* Use the property context to extract useful information and inject that into the annotation. |
| 15 |
*/ |
| 16 |
class AugmentDiscriminators |
| 17 |
{ |
| 18 |
public function __invoke(Analysis $analysis): void |
| 19 |
{ |
| 20 |
$discriminators = $analysis->getAnnotationsOfType(OA\Discriminator::class); |
| 21 |
|
| 22 |
foreach ($discriminators as $discriminator) { |
| 23 |
if (!Generator::isDefault($discriminator->mapping)) { |
| 24 |
foreach ($discriminator->mapping as $value => $type) { |
| 25 |
if (is_string($type) && $typeSchema = $analysis->getAnnotationForSource($type)) { |
| 26 |
$discriminator->mapping[$value] = OA\Components::ref($typeSchema); |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
} |