1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Aweapi\Openapi\Objects; |
6
|
|
|
|
7
|
|
|
use Aweapi\Openapi\Extensions; |
8
|
|
|
use Aweapi\Openapi\ValueObject; |
9
|
|
|
|
10
|
|
|
final class Operation extends ValueObject |
11
|
|
|
{ |
12
|
|
|
use Properties\OptionalDeprecationStatus; |
13
|
|
|
use Properties\OptionalDescription; |
14
|
|
|
use Properties\OptionalExternalDocs; |
15
|
|
|
use Properties\OptionalExtensions; |
16
|
|
|
use Properties\OptionalServers; |
17
|
|
|
use Properties\OptionalSummary; |
18
|
|
|
use Properties\OptionalSecurityRequirements; |
19
|
|
|
use Properties\OptionalParameterCollection; |
20
|
|
|
use Properties\OptionalCallbacks; |
21
|
|
|
|
22
|
|
|
private $operationId; |
23
|
|
|
|
24
|
|
|
private $requestBody; |
25
|
|
|
|
26
|
|
|
private $responses; |
27
|
|
|
|
28
|
|
|
private $tags; |
29
|
|
|
|
30
|
6 |
|
public function __construct( |
31
|
|
|
OperationResponses $responses, |
32
|
|
|
RequestBody $requestBody = null, |
33
|
|
|
array $tags = [], |
34
|
|
|
string $operationId = null, |
35
|
|
|
string $summary = null, |
36
|
|
|
string $description = null, |
37
|
|
|
bool $deprecated = false, |
38
|
|
|
ParameterCollection $parameters = null, |
39
|
|
|
SecurityRequirementCollection $security = null, |
40
|
|
|
CallbackRequests $callbacks = null, |
41
|
|
|
ServerCollection $servers = null, |
42
|
|
|
ExternalDocumentation $externalDocs = null, |
43
|
|
|
Extensions $extensions = null |
44
|
|
|
) { |
45
|
6 |
|
$this->responses = $responses; |
46
|
6 |
|
$this->requestBody = $requestBody; |
47
|
6 |
|
$this->tags = $tags; |
48
|
6 |
|
$this->operationId = $operationId; |
49
|
6 |
|
$this->summary = $summary; |
50
|
6 |
|
$this->description = $description; |
51
|
6 |
|
$this->deprecated = $deprecated; |
52
|
6 |
|
$this->parameters = $parameters; |
53
|
6 |
|
$this->security = $security; |
54
|
6 |
|
$this->callbacks = $callbacks; |
55
|
6 |
|
$this->servers = $servers; |
56
|
6 |
|
$this->externalDocs = $externalDocs; |
57
|
6 |
|
$this->extensions = $extensions; |
58
|
|
|
} |
59
|
|
|
|
60
|
2 |
|
public function getOperationId(): string |
61
|
|
|
{ |
62
|
2 |
|
return $this->operationId; |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
public function getRequestBody(): ValueObject |
66
|
|
|
{ |
67
|
2 |
|
return $this->requestBody; |
68
|
|
|
} |
69
|
|
|
|
70
|
6 |
|
public function getResponses(): OperationResponses |
71
|
|
|
{ |
72
|
6 |
|
return $this->responses; |
73
|
|
|
} |
74
|
|
|
|
75
|
6 |
|
public function getTags(): array |
76
|
|
|
{ |
77
|
6 |
|
return $this->tags; |
78
|
|
|
} |
79
|
|
|
|
80
|
6 |
|
public function hasOperationId(): bool |
81
|
|
|
{ |
82
|
6 |
|
return isset($this->operationId); |
83
|
|
|
} |
84
|
|
|
|
85
|
6 |
|
public function hasRequestBody(): bool |
86
|
|
|
{ |
87
|
6 |
|
return isset($this->requestBody); |
88
|
|
|
} |
89
|
|
|
|
90
|
6 |
|
public function jsonSerialize(): ?array |
91
|
|
|
{ |
92
|
6 |
|
return $this->extendedProperties(parent::jsonSerialize()); |
93
|
|
|
} |
94
|
|
|
|
95
|
6 |
|
protected function normalizeOptionalProperties(): array |
96
|
|
|
{ |
97
|
|
|
return [ |
98
|
6 |
|
'requestBody' => $this->hasRequestBody() ? $this->getRequestBody()->jsonSerialize() : null, |
99
|
6 |
|
'tags' => $this->getTags(), |
100
|
6 |
|
'operationId' => $this->hasOperationId() ? $this->getOperationId() : null, |
101
|
6 |
|
'summary' => $this->getNormalizedSummary(), |
102
|
6 |
|
'description' => $this->getNormalizedDescription(), |
103
|
6 |
|
'deprecated' => $this->isDeprecated() ?: null, |
104
|
6 |
|
'parameters' => $this->getNormalizedParameters(), |
105
|
6 |
|
'security' => $this->getNormalizedSecurity(), |
106
|
6 |
|
'callbacks' => $this->getNormalizedCallbacks(), |
107
|
6 |
|
'servers' => $this->getNormalizedServers(), |
108
|
6 |
|
'externalDocs' => $this->getNormalizedExternalDocs(), |
109
|
|
|
]; |
110
|
|
|
} |
111
|
|
|
|
112
|
6 |
|
protected function normalizeRequiredProperties(): array |
113
|
|
|
{ |
114
|
|
|
return [ |
115
|
6 |
|
'responses' => $this->getResponses()->jsonSerialize() ?: self::emptyObject(), |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|