Debian Codegraph @

vendor/zircote/swagger-php/src/Annotations/PathItem.php

raw
1 <?php declare(strict_types=1);
2
3 /**
4 * @license Apache 2.0
5 */
6
7 namespace OpenApi\Annotations;
8
9 use OpenApi\Generator;
10
11 /**
12 * Describes the operations available on a single path.
13 *
14 * A Path Item may be empty, due to ACL constraints.
15 * The path itself is still exposed to the documentation viewer, but they will not know which operations and parameters are available.
16 *
17 * @see [Path Item Object](https://spec.openapis.org/oas/v3.1.1.html#path-item-object)
18 *
19 * @Annotation
20 */
21 class PathItem extends AbstractAnnotation
22 {
23 /**
24 * @see [Reference Object](https://spec.openapis.org/oas/v3.1.1.html#reference-object)
25 *
26 * @var string|class-string|object
27 */
28 public $ref = Generator::UNDEFINED;
29
30 /**
31 * An optional, string summary, intended to apply to all operations in this path.
32 *
33 * @var string
34 */
35 public $summary = Generator::UNDEFINED;
36
37 /**
38 * An optional, string description, intended to apply to all operations in this path.
39 *
40 * @var string
41 */
42 public $description = Generator::UNDEFINED;
43
44 /**
45 * Key for the Path Object (OpenApi->paths array).
46 *
47 * @var string
48 */
49 public $path = Generator::UNDEFINED;
50
51 /**
52 * A definition of a GET operation on this path.
53 *
54 * @var Get
55 */
56 public $get = Generator::UNDEFINED;
57
58 /**
59 * A definition of a PUT operation on this path.
60 *
61 * @var Put
62 */
63 public $put = Generator::UNDEFINED;
64
65 /**
66 * A definition of a POST operation on this path.
67 *
68 * @var Post
69 */
70 public $post = Generator::UNDEFINED;
71
72 /**
73 * A definition of a DELETE operation on this path.
74 *
75 * @var Delete
76 */
77 public $delete = Generator::UNDEFINED;
78
79 /**
80 * A definition of a OPTIONS operation on this path.
81 *
82 * @var Options
83 */
84 public $options = Generator::UNDEFINED;
85
86 /**
87 * A definition of a HEAD operation on this path.
88 *
89 * @var Head
90 */
91 public $head = Generator::UNDEFINED;
92
93 /**
94 * A definition of a PATCH operation on this path.
95 *
96 * @var Patch
97 */
98 public $patch = Generator::UNDEFINED;
99
100 /**
101 * A definition of a TRACE operation on this path.
102 *
103 * @var Trace
104 */
105 public $trace = Generator::UNDEFINED;
106
107 /**
108 * A definition of a QUERY operation on this path.
109 *
110 * @since OpenAPI 3.2.0
111 * @var Query
112 */
113 public $query = Generator::UNDEFINED;
114
115 /**
116 * An alternative server array to service all operations in this path.
117 *
118 * @var list<Server>
119 */
120 public $servers = Generator::UNDEFINED;
121
122 /**
123 * A list of parameters that are applicable for all the operations described under this path.
124 *
125 * These parameters can be overridden at the operation level, but cannot be removed there.
126 * The list must not include duplicated parameters.
127 * A unique parameter is defined by a combination of a name and location.
128 * The list can use the Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters.
129 *
130 * @var list<Parameter>
131 */
132 public $parameters = Generator::UNDEFINED;
133
134 /**
135 * @inheritdoc
136 */
137 public static $_types = [
138 'path' => 'string',
139 'summary' => 'string',
140 ];
141
142 /**
143 * @inheritdoc
144 */
145 public static $_nested = [
146 Get::class => 'get',
147 Post::class => 'post',
148 Put::class => 'put',
149 Delete::class => 'delete',
150 Patch::class => 'patch',
151 Trace::class => 'trace',
152 Head::class => 'head',
153 Options::class => 'options',
154 Query::class => 'query',
155 Parameter::class => ['parameters'],
156 PathParameter::class => ['parameters'],
157 Server::class => ['servers'],
158 Attachable::class => ['attachables'],
159 ];
160
161 /**
162 * @inheritdoc
163 */
164 public static $_parents = [
165 OpenApi::class,
166 ];
167
168 /**
169 * Returns a list of all operations (all methods) for this path item.
170 *
171 * @return list<Operation>
172 */
173 public function operations(): array
174 {
175 $operations = [];
176 foreach (PathItem::$_nested as $className => $property) {
177 if (is_subclass_of($className, Operation::class) && !Generator::isDefault($this->{$property})) {
178 $operations[] = $this->{$property};
179 }
180 }
181
182 return $operations;
183 }
184
185 public function jsonSerialize(): \stdClass
186 {
187 $data = parent::jsonSerialize();
188
189 if ($this->_context->isVersion(['3.0.x', '3.1.x'])) {
190 unset($data->query);
191 }
192
193 return $data;
194 }
195 }