forked from zircote/swagger-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackportConstants.php
36 lines (30 loc) · 959 Bytes
/
BackportConstants.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php declare(strict_types=1);
/**
* @license Apache 2.0
*/
namespace OpenApi\Processors;
use OpenApi\Analysis;
use OpenApi\Annotations\OpenApi;
use OpenApi\Annotations\Property as AnnotationSchema;
use OpenApi\Attributes\Property as AttributeSchema;
use OpenApi\Generator;
/**
* Transform const keywords to enum in OpenApi versions < 3.1.0.
*/
class BackportConstants
{
public function __invoke(Analysis $analysis)
{
/** @var AnnotationSchema[] $schemas */
$schemas = $analysis->getAnnotationsOfType([AnnotationSchema::class, AttributeSchema::class], true);
foreach ($schemas as $schema) {
if (Generator::isDefault($schema->const)) {
continue;
}
if (version_compare($analysis->context->version, OpenApi::VERSION_3_1_0, '<')) {
$schema->enum = [$schema->const];
$schema->const = Generator::UNDEFINED;
}
}
}
}