1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the API Platform project. |
5
|
|
|
* |
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace ApiPlatform\Core\OpenApi; |
15
|
|
|
|
16
|
|
|
class Operation |
17
|
|
|
{ |
18
|
|
|
private $tags; |
19
|
|
|
private $summary; |
20
|
|
|
private $description; |
21
|
|
|
private $operationId; |
22
|
|
|
/** |
23
|
|
|
* @Parameter | Reference |
24
|
|
|
*/ |
25
|
|
|
private $parameters; |
26
|
|
|
|
27
|
|
|
private $requestBody; |
28
|
|
|
private $responses; |
29
|
|
|
private $callbacks; |
30
|
|
|
private $deprecated; |
31
|
|
|
private $security; |
32
|
|
|
private $servers; |
33
|
|
|
private $externalDocs; |
34
|
|
|
|
35
|
|
|
public function __construct(string $operationId = null, array $tags = [], array $responses = [], string $summary = '', string $description = '', $externalDocs = [], array $parameters = [], RequestBody $requestBody = null, $callbacks = [], bool $deprecated = false, $security = [], array $servers = []) |
36
|
|
|
{ |
37
|
|
|
$this->tags = $tags; |
38
|
|
|
$this->summary = $summary; |
39
|
|
|
$this->description = $description; |
40
|
|
|
$this->operationId = $operationId; |
41
|
|
|
$this->parameters = $parameters; |
42
|
|
|
$this->requestBody = $requestBody; |
43
|
|
|
$this->responses = $responses; |
44
|
|
|
$this->callbacks = $callbacks; |
45
|
|
|
$this->deprecated = $deprecated; |
46
|
|
|
$this->security = $security; |
47
|
|
|
$this->servers = $servers; |
48
|
|
|
$this->externalDocs = $externalDocs; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public static function fromContext(array $context = []) |
52
|
|
|
{ |
53
|
|
|
$operation = new self(); |
54
|
|
|
foreach ($context as $property => $value) { |
55
|
|
|
if (isset($operation->{$property})) { |
56
|
|
|
$operation->{$property} = $value; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $operation; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getOperationId() |
64
|
|
|
{ |
65
|
|
|
return $this->operationId; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setDescription(string $description) |
69
|
|
|
{ |
70
|
|
|
$this->description = $description; |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setOperationId(string $operationId) |
76
|
|
|
{ |
77
|
|
|
$this->operationId = $operationId; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function addTag(string $tag) |
83
|
|
|
{ |
84
|
|
|
$this->tags[] = $tag; |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function isDeprecated(bool $deprecated) |
90
|
|
|
{ |
91
|
|
|
$this->deprecated = $deprecated; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function addParameter(Parameter $parameter) |
97
|
|
|
{ |
98
|
|
|
$this->parameters[] = $parameter; |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function addResponse(Response $response, $status = 'default') |
104
|
|
|
{ |
105
|
|
|
$this->responses[$status] = $response; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function setRequestBody(RequestBody $requestBody) |
111
|
|
|
{ |
112
|
|
|
$this->requestBody = $requestBody; |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|