-
-
Notifications
You must be signed in to change notification settings - Fork 899
Expand file tree
/
Copy pathNullablePropertyProcessor.php
More file actions
47 lines (40 loc) · 1.36 KB
/
NullablePropertyProcessor.php
File metadata and controls
47 lines (40 loc) · 1.36 KB
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
37
38
39
40
41
42
43
44
45
46
47
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Processor;
use OpenApi\Analysis;
use OpenApi\Annotations as OA;
use OpenApi\Generator;
/**
* Processor to clean up the generated OpenAPI documentation for nullable properties.
*/
final class NullablePropertyProcessor
{
public function __invoke(Analysis $analysis): void
{
if (Generator::isDefault($analysis->openapi->components) || Generator::isDefault($analysis->openapi->components->schemas)) {
return;
}
/** @var OA\Schema[] $schemas */
$schemas = $analysis->openapi->components->schemas;
foreach ($schemas as $schema) {
if (Generator::UNDEFINED === $schema->properties) {
continue;
}
foreach ($schema->properties as $property) {
if (Generator::UNDEFINED !== $property->nullable) {
if (!$property->nullable) {
// if already false mark it as undefined (so it does not show up as `nullable: false`)
$property->nullable = Generator::UNDEFINED; /* @phpstan-ignore-line */
}
}
}
}
}
}