-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServerVariable.php
More file actions
56 lines (45 loc) · 1.57 KB
/
ServerVariable.php
File metadata and controls
56 lines (45 loc) · 1.57 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
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace Membrane\OpenAPIReader\ValueObject\Valid\V31;
use Membrane\OpenAPIReader\Exception\InvalidOpenAPI;
use Membrane\OpenAPIReader\ValueObject\Partial;
use Membrane\OpenAPIReader\ValueObject\Valid\Identifier;
use Membrane\OpenAPIReader\ValueObject\Valid\Validated;
use Membrane\OpenAPIReader\ValueObject\Valid\Warning;
final class ServerVariable extends Validated
{
/** REQUIRED */
public readonly string $default;
/**
* If not null:
* - It SHOULD NOT be empty
* - It SHOULD contain the "default" value
* @var list<string>|null
*/
public readonly array|null $enum;
public function __construct(
Identifier $identifier,
Partial\ServerVariable $serverVariable,
) {
parent::__construct($identifier);
if (!isset($serverVariable->default)) {
throw InvalidOpenAPI::serverVariableMissingDefault($identifier);
}
$this->default = $serverVariable->default;
if (isset($serverVariable->enum)) {
if (empty($serverVariable->enum)) {
$this->addWarning(
'If "enum" is defined, it SHOULD NOT be empty',
Warning::EMPTY_ENUM,
);
}
if (!in_array($serverVariable->default, $serverVariable->enum)) {
$this->addWarning(
'If "enum" is defined, the "default" SHOULD exist within it.',
Warning::IMPOSSIBLE_DEFAULT
);
}
}
$this->enum = $serverVariable->enum;
}
}