Debian Codegraph @

vendor/zircote/swagger-php/src/Processors/AugmentProperties.php

raw
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\Context;
12 use OpenApi\Generator;
13 use OpenApi\GeneratorAwareInterface;
14 use OpenApi\GeneratorAwareTrait;
15
16 /**
17 * Use the property context to extract useful information and inject that into the annotation.
18 */
19 class AugmentProperties implements GeneratorAwareInterface
20 {
21 use Concerns\DocblockTrait;
22
23 use Concerns\RefTrait;
24
25 use GeneratorAwareTrait;
26
27 public function __invoke(Analysis $analysis): void
28 {
29 $properties = $analysis->getAnnotationsOfType(OA\Property::class);
30
31 foreach ($properties as $property) {
32 $context = $property->_context;
33 $reflector = $context->reflector;
34
35 if (Generator::isDefault($property->property)) {
36 $property->property = $property->_context->property;
37 }
38
39 if ($property->encoding instanceof OA\Encoding) {
40 $property->encoding->property = $property->property;
41 }
42
43 if (Generator::isDefault($property->const) && $reflector instanceof \ReflectionClassConstant) {
44 $property->const = $reflector->getValue();
45 }
46
47 if (Generator::isDefault($property->description)) {
48 $typeAndDescription = $this->parseVarLine((string) $context->comment);
49
50 if ($typeAndDescription['description']) {
51 $property->description = trim($typeAndDescription['description']);
52 } elseif ($this->isDocblockRoot($property)) {
53 $property->description = $this->parseDocblock($context->comment);
54 }
55 } elseif (null === $property->description) {
56 $property->description = Generator::UNDEFINED;
57 }
58
59 if (!Generator::isDefault($property->ref)) {
60 continue;
61 }
62
63 if (Generator::isDefault($property->type)) {
64 $this->generator->getTypeResolver()->augmentSchemaType($analysis, $property);
65 }
66
67 $this->generator->getTypeResolver()->mapNativeType($property, $property->type);
68
69 if (Generator::isDefault($property->example) && ($example = $this->extractExampleDescription((string) $context->comment))) {
70 $property->example = $example;
71 }
72
73 if (Generator::isDefault($property->deprecated) && ($deprecated = $this->isDeprecated($context->comment))) {
74 $property->deprecated = $deprecated;
75 }
76 }
77 }
78 }