-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperation.php
376 lines (343 loc) · 13.5 KB
/
Operation.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
namespace Zerotoprod\DataModelOpenapi30;
use Zerotoprod\DataModel\Describe;
use Zerotoprod\DataModel\PropertyRequiredException;
use Zerotoprod\DataModelOpenapi30\Helpers\DataModel;
/**
* Describes a single API operation on a path.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#operation-object
*/
class Operation
{
use DataModel;
/**
* A list of tags for API documentation control. Tags can be used
* for logical grouping of operations by resources or any other
* qualifier.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $tags
*/
public const tags = 'tags';
/**
* A list of tags for API documentation control. Tags can be used
* for logical grouping of operations by resources or any other
* qualifier.
*
* @var string[] $tags
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['default' => []])]
public array $tags;
/**
* A short summary of what the operation does.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $summary
*/
public const summary = 'summary';
/**
* A short summary of what the operation does.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['nullable'])]
public ?string $summary;
/**
* A verbose explanation of the operation behavior. [CommonMark]
* syntax _MAY_ be used for rich text representation.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see https://spec.commonmark.org/
* @see $description
*/
public const description = 'description';
/**
* A verbose explanation of the operation behavior. [CommonMark]
* syntax _MAY_ be used for rich text representation.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see https://spec.commonmark.org/
*/
#[Describe(['nullable'])]
public ?string $description;
/**
* Additional external documentation for this operation.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $externalDocs
*/
public const externalDocs = 'externalDocs';
/**
* Additional external documentation for this operation.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['nullable'])]
public ?ExternalDocumentation $externalDocs;
/**
* Unique string used to identify the operation. The id _MUST_ be unique
* among all operations described in the API. The `operationId` value is
* **case-sensitive**. Tools and libraries _MAY_ use the `operationId`
* to uniquely identify an operation, therefore, it is _RECOMMENDED_
* to follow common programming naming conventions.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $operationId
*/
public const operationId = 'operationId';
/**
* Unique string used to identify the operation. The id _MUST_ be unique
* among all operations described in the API. The `operationId` value is
* **case-sensitive**. Tools and libraries _MAY_ use the `operationId`
* to uniquely identify an operation, therefore, it is _RECOMMENDED_
* to follow common programming naming conventions.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['nullable'])]
public ?string $operationId;
/**
* A list of parameters that are applicable for this operation. If a parameter
* is already defined in the Path Item, the new definition will override it
* but can never remove it. The list _MUST NOT_ include duplicated
* parameters. A unique parameter is defined by a combination of a
* name and location. The list can use the Reference Object to link
* to parameters that are defined in the OpenAPI Object’s
* `components.parameters`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $parameters
*/
public const parameters = 'parameters';
/**
* A list of parameters that are applicable for this operation. If a parameter
* is already defined in the Path Item, the new definition will override it
* but can never remove it. The list _MUST NOT_ include duplicated
* parameters. A unique parameter is defined by a combination of a
* name and location. The list can use the Reference Object to link
* to parameters that are defined in the OpenAPI Object’s
* `components.parameters`.
*
* @var array<string, Parameter|Reference> $parameters
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['cast' => [self::class, 'parameters']])]
public array $parameters;
/**
* A list of parameters that are applicable for this operation. If a parameter
* is already defined in the Path Item, the new definition will override it
* but can never remove it. The list _MUST NOT_ include duplicated
* parameters. A unique parameter is defined by a combination of a
* name and location. The list can use the Reference Object to link
* to parameters that are defined in the OpenAPI Object’s
* `components.parameters`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $parameters
*/
public static function parameters($value, array $context): array
{
return isset($context[self::parameters])
? array_map(
static fn($value) => isset($value[Reference::ref])
? Reference::from($value)
: Parameter::from($value),
$value
)
: [];
}
/**
* The request body applicable for this operation. The `requestBody` is only supported
* in HTTP methods where the HTTP 1.1 specification [RFC7231] Section 4.3.1 has
* explicitly defined semantics for request bodies. In other cases where the
* HTTP spec is vague (such as GET, HEAD and DELETE), `requestBody` _SHALL_ be
* ignored by consumers.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $requestBody
*/
public const requestBody = 'requestBody';
/**
* The request body applicable for this operation. The `requestBody` is only supported
* in HTTP methods where the HTTP 1.1 specification [RFC7231] Section 4.3.1 has
* explicitly defined semantics for request bodies. In other cases where the
* HTTP spec is vague (such as GET, HEAD and DELETE), `requestBody` _SHALL_ be
* ignored by consumers.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['cast' => [self::class, 'requestBody']])]
public null|RequestBody|Reference $requestBody;
/**
* A list of parameters that are applicable for this operation. If a parameter
* is already defined in the Path Item, the new definition will override it
* but can never remove it. The list _MUST NOT_ include duplicated
* parameters. A unique parameter is defined by a combination of a
* name and location. The list can use the Reference Object to link
* to parameters that are defined in the OpenAPI Object’s
* `components.parameters`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $requestBody
*/
public static function requestBody($value, array $context): null|RequestBody|Reference
{
if (isset($context[self::requestBody])) {
return isset($context[self::requestBody][Reference::ref])
? Reference::from($value)
: RequestBody::from($value);
}
return null;
}
/**
* **REQUIRED**. The list of possible responses as they are returned
* from executing this operation.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $responses
*/
public const responses = 'responses';
/**
* **REQUIRED**. The list of possible responses as they are returned
* from executing this operation.
*
* @var array<string, Response|Reference> $examples
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['cast' => [self::class, 'responses']])]
public array $responses;
/**
* **REQUIRED**. The list of possible responses as they are returned
* from executing this operation.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $responses
*/
public static function responses($value, array $context): array
{
if (!isset($context[self::responses])) {
throw new PropertyRequiredException('Property `$responses` is required.');
}
return array_map(
static fn($value) => isset($value[Reference::ref])
? Reference::from($value)
: Response::from($value),
$value
);
}
/**
* A map of possible out-of band callbacks related to the parent operation.
* The key is a unique identifier for the Callback Object. Each value in
* the map is a Callback Object that describes a request that may be
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $callbacks
*/
public const callbacks = 'callbacks';
/**
* A map of possible out-of band callbacks related to the parent operation.
* The key is a unique identifier for the Callback Object. Each value in
* the map is a Callback Object that describes a request that may be
* initiated by the API provider and the expected responses.
*
* @var array<string, array<string, PathItem>> $callbacks
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['cast' => [self::class, 'callbacks']])]
public array $callbacks;
/**
* A map of possible out-of band callbacks related to the parent operation.
* The key is a unique identifier for the Callback Object. Each value in
* the map is a Callback Object that describes a request that may be
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $callbacks
*/
public static function callbacks($value, array $context): array
{
return isset($context[self::callbacks])
? array_map(
static fn($value) => isset($value[Reference::ref])
? Reference::from($value)
: array_map(static fn($item) => PathItem::from($item), $value),
$value
)
: [];
}
/**
* Declares this operation to be deprecated. Consumers _SHOULD_ refrain
* from usage of the declared operation. Default value is `false`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $deprecated
*/
public const deprecated = 'deprecated';
/**
* Declares this operation to be deprecated. Consumers _SHOULD_ refrain
* from usage of the declared operation. Default value is `false`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['default' => false])]
public bool $deprecated;
/**
* A declaration of which security mechanisms can be used for this operation.
* The list of values includes alternative Security Requirement Objects that
* can be used. Only one of the Security Requirement Objects need to be
* satisfied to authorize a request. To make security optional, an
* empty security requirement (`{}`) can be included in the array.
* This definition overrides any declared top-level security.
* To remove a top-level `security` declaration, an empty
* array can be used.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $security
*/
public const security = 'security';
/**
* A declaration of which security mechanisms can be used for this operation.
* The list of values includes alternative Security Requirement Objects that
* can be used. Only one of the Security Requirement Objects need to be
* satisfied to authorize a request. To make security optional, an
* empty security requirement (`{}`) can be included in the array.
* This definition overrides any declared top-level security.
* To remove a top-level `security` declaration, an empty
* array can be used.
*
* @var array<string, string[]> $security
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe(['default' => []])]
public array $security;
/**
* An alternative `servers` array to service this operation. If a `servers`
* array is specified at the Path Item Object or OpenAPI Object level,
* it will be overridden by this value.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
* @see $servers
*/
public const servers = 'servers';
/**
* An alternative `servers` array to service this operation. If a `servers`
* array is specified at the Path Item Object or OpenAPI Object level,
* it will be overridden by this value.
*
* @var Server[]
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-7
*/
#[Describe([
'cast' => [self::class, 'mapOf'],
'type' => Server::class,
'default' => []
])]
public array $servers;
}