-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parameter.php
435 lines (399 loc) · 17.1 KB
/
Parameter.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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?php
namespace Zerotoprod\DataModelOpenapi30;
use Zerotoprod\DataModel\Describe;
use Zerotoprod\DataModelOpenapi30\Helpers\DataModel;
/**
* Describes a single operation parameter.
*
* A unique parameter is defined by a combination of a name and location.
*
* See Appendix E for a detailed examination of percent-encoding concerns,
* including interactions with the `application/x-www-form-urlencoded` query string format.
*
* The rules for serialization of the parameter are specified in one of two ways.
* Parameter Objects ***_MUST_*** include either a `content` field or a `schema` field, but
* not both. See Appendix B for a discussion of converting values of various
* types to string representations.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#parameter-object
* @see https://spec.openapis.org/oas/v3.0.4.html#parameter-name
* @see https://spec.openapis.org/oas/v3.0.4.html#parameter-in
* @see https://spec.openapis.org/oas/v3.0.4.html#appendix-e-percent-encoding-and-form-media-types
*
*/
class Parameter
{
use DataModel;
/**
* **REQUIRED**. The name of the parameter. Parameter names are case-sensitive.
*
* - If `in` is `"path"`, the name field _MUST_ correspond to a template expression
* occurring within the path field in the Paths Object. See Path Templating
* for further information.
* - If `in` is `"header"` and the name field is `"Accept"`, `"Content-Type"` or
* `"Authorization"`, the parameter definition _SHALL_ be ignored.
* - For all other cases, the `name` corresponds to the parameter name used
* by the `in` field.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#parameter-in
* @see https://spec.openapis.org/oas/v3.0.4.html#paths-path
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields:~:text=field%20in%20the-,Paths%20Object,-.%20See%20Path%20Templating
* @see https://spec.openapis.org/oas/v3.0.4.html#path-templating
* @see $name
*/
public const name = 'name';
/**
* **REQUIRED**. The name of the parameter. Parameter names are case-sensitive.
*
* - If `in` is `"path"`, the name field _MUST_ correspond to a template expression
* occurring within the path field in the Paths Object. See Path Templating
* for further information.
* - If `in` is `"header"` and the name field is `"Accept"`, `"Content-Type"` or
* `"Authorization"`, the parameter definition _SHALL_ be ignored.
* - For all other cases, the `name` corresponds to the parameter name used
* by the `in` field.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#parameter-in
* @see https://spec.openapis.org/oas/v3.0.4.html#paths-path
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields:~:text=field%20in%20the-,Paths%20Object,-.%20See%20Path%20Templating
* @see https://spec.openapis.org/oas/v3.0.4.html#path-templating
*/
#[Describe(['required'])]
public string $name;
/**
* **REQUIRED**. The location of the parameter. Possible values are `"query"`,
* `"header"`, `"path"` or `"cookie"`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see $in
*/
public const in = 'in';
/**
* **REQUIRED**. The location of the parameter. Possible values are `"query"`,
* `"header"`, `"path"` or `"cookie"`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
*/
#[Describe(['required'])]
public string $in;
/**
* A brief description of the parameter. This could contain examples of use.
* [CommonMark] syntax _MAY_ be used for rich text representation.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.commonmark.org/
* @see $description
*/
public const description = 'description';
/**
* A brief description of the parameter. This could contain examples of use.
* [CommonMark] syntax _MAY_ be used for rich text representation.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.commonmark.org/
*/
#[Describe(['nullable'])]
public ?string $description;
/**
* Determines whether this parameter is mandatory. If the parameter
* location is `"path"`, this field is **REQUIRED** and its value ***_MUST_***
* be `true`. Otherwise, the field _MAY_ be included and its default
* value is `false`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#parameter-in
* @see $required
*/
public const required = 'required';
/**
* Determines whether this parameter is mandatory. If the parameter
* location is `"path"`, this field is **REQUIRED** and its value ***_MUST_***
* be `true`. Otherwise, the field _MAY_ be included and its default
* value is `false`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#parameter-in
*/
#[Describe(['default' => false])]
public bool $required;
/**
* Specifies that a parameter is deprecated and _SHOULD_ be transitioned
* out of usage. Default value is `false`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see $deprecated
*/
public const deprecated = 'deprecated';
/**
* Specifies that a parameter is deprecated and _SHOULD_ be transitioned
* out of usage. Default value is `false`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
*/
#[Describe(['default' => false])]
public bool $deprecated;
/**
* If `true`, clients _MAY_ pass a zero-length string value in place
* of parameters that would otherwise be omitted entirely, which the
* server _SHOULD_ interpret as the parameter being unused.
* Default value is `false`. If `style` is used, and if behavior
* is n/a (cannot be serialized), the value of `allowEmptyValue`
* _SHALL_ be ignored. Interactions between this field
* and the parameter’s Schema Object are implementation-defined.
* This field is valid only for query parameters. Use of
* this field is ***NOT _RECOMMENDED_***, and it is likely
* to be removed in a later revision.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#parameter-style
* @see https://spec.openapis.org/oas/v3.0.4.html#style-examples
* @see $allowEmptyValue
*/
public const allowEmptyValue = 'allowEmptyValue';
/**
* If `true`, clients _MAY_ pass a zero-length string value in place
* of parameters that would otherwise be omitted entirely, which the
* server _SHOULD_ interpret as the parameter being unused.
* Default value is `false`. If `style` is used, and if behavior
* is n/a (cannot be serialized), the value of `allowEmptyValue`
* _SHALL_ be ignored. Interactions between this field
* and the parameter’s Schema Object are implementation-defined.
* This field is valid only for query parameters. Use of
* this field is ***NOT _RECOMMENDED_***, and it is likely
* to be removed in a later revision.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#parameter-style
* @see https://spec.openapis.org/oas/v3.0.4.html#style-examples
*/
#[Describe(['default' => false])]
public bool $allowEmptyValue;
/**
* Describes how the parameter value will be serialized depending on the
* type of the parameter value. Default values (based on value of `in`):
* for `"query"` - `"form"`; for `"path"` - `"simple"`; for `"header"`
* - `"simple"`; for `"cookie"` - `"form"`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
* @see $style
*/
public const style = 'style';
/**
* Describes how the parameter value will be serialized depending on the
* type of the parameter value. Default values (based on value of `in`):
* for `"query"` - `"form"`; for `"path"` - `"simple"`; for `"header"`
* - `"simple"`; for `"cookie"` - `"form"`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
*/
#[Describe(['cast' => [self::class, 'style']])]
public ?string $style;
/**
* When this is `true`, parameter values of type `array` or `object` generate separate
* parameters for each value of the array or key-value pair of the map. For other
* types of parameters this field has no effect. When `style` is `"form"`, the
* default value is `true`. For all other styles, the default value is `false`.
* Note that despite `false` being the default for `deepObject`, the
* combination of false with `deepObject` is undefined.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
* @see $style
*/
public static function style($value, $context): ?string
{
if (!$value && isset($context[self::in])) {
return match ($context[self::in]) {
'query', 'cookie' => 'form',
'path', 'header' => 'simple',
default => null,
};
}
return is_string($value)
? $value
: null;
}
/**
* When this is `true`, parameter values of type `array` or `object` generate separate
* parameters for each value of the array or key-value pair of the map. For other
* types of parameters this field has no effect. When `style` is `"form"`, the
* default value is `true`. For all other styles, the default value is `false`.
* Note that despite `false` being the default for `deepObject`, the
* combination of false with `deepObject` is undefined.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
* @see $explode
*/
public const explode = 'explode';
/**
* When this is `true`, parameter values of type `array` or `object` generate separate
* parameters for each value of the array or key-value pair of the map. For other
* types of parameters this field has no effect. When `style` is `"form"`, the
* default value is `true`. For all other styles, the default value is `false`.
* Note that despite `false` being the default for `deepObject`, the
* combination of false with `deepObject` is undefined.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
*/
#[Describe(['cast' => [self::class, 'explode']])]
public bool $explode;
/**
* Describes how the parameter value will be serialized depending on the
* type of the parameter value. Default values (based on value of `in`):
* for `"query"` - `"form"`; for `"path"` - `"simple"`; for `"header"`
* - `"simple"`; for `"cookie"` - `"form"`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
* @see $explode
*/
public static function explode($value, $context): bool
{
if (empty($value) && !is_bool($value) && isset($context[self::style])) {
return $context[self::style] === 'form';
}
return is_bool($value)
? $value
: false;
}
/**
* When this is `true`, parameter values are serialized using reserved expansion, as
* defined by [RFC6570] Section 3.2.3, which allows RFC3986’s reserved character set,
* as well as percent-encoded triples, to pass through unchanged, while still
* percent-encoding all other disallowed characters (including `%` outside of
* percent-encoded triples). Applications are still responsible for
* percent-encoding reserved characters that are not allowed in the
* query string (`[`, `]`, `#`), or have a special meaning in
* `application/x-www-form-urlencoded` (`-`, `&`, `+`); see
* Appendices C and E for details. This field only applies
* to parameters with an `in` value of `query`. The
* default value is `false`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
* @see $allowReserved
*/
public const allowReserved = 'allowReserved';
/**
* When this is `true`, parameter values are serialized using reserved expansion, as
* defined by [RFC6570] Section 3.2.3, which allows RFC3986’s reserved character set,
* as well as percent-encoded triples, to pass through unchanged, while still
* percent-encoding all other disallowed characters (including `%` outside of
* percent-encoded triples). Applications are still responsible for
* percent-encoding reserved characters that are not allowed in the
* query string (`[`, `]`, `#`), or have a special meaning in
* `application/x-www-form-urlencoded` (`-`, `&`, `+`); see
* Appendices C and E for details. This field only applies
* to parameters with an `in` value of `query`. The
* default value is `false`.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
*/
#[Describe(['default' => false])]
public bool $allowReserved;
/**
* The schema defining the type used for the parameter.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
* @see $schema
*/
public const schema = 'schema';
/**
* The schema defining the type used for the parameter.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
*/
#[Describe(['cast' => [self::class, 'schema']])]
public null|Schema|Reference $schema;
/**
* The schema defining the type used for the parameter.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-schema
* @see $schema
*/
public static function schema($value, array $context): Schema|Reference|null
{
if (!isset($context[self::schema])) {
return null;
}
return isset($value[Reference::ref])
? Reference::from($value)
: Schema::from($value);
}
/**
* Example of the parameter’s potential value; see Working With Examples.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#working-with-examples
* @see $example
*/
public const example = 'example';
/**
* Example of the parameter’s potential value; see Working With Examples.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#working-with-examples
*/
#[Describe(['nullable'])]
public mixed $example;
/**
* Examples of the parameter’s potential value; see Working With Examples.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see $examples
*/
public const examples = 'examples';
/**
* Example of the parameter’s potential value; see Working With Examples.
*
* @var array<string, Example|Reference> $examples
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#working-with-examples
*/
#[Describe(['cast' => [self::class, 'examples']])]
public array $examples;
/**
* Example of the parameter’s potential value; see Working With Examples.
*
* @return array<string, Example|Reference>
*
* @link https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields
* @see https://spec.openapis.org/oas/v3.0.4.html#working-with-examples
* @see $examples
*/
public static function examples($value, array $context): array
{
return isset($context[self::examples])
? array_map(
static fn($value) => isset($value[Reference::ref])
? Reference::from($value)
: Example::from($value),
$value
)
: [];
}
/**
* A map containing the representations for the parameter. The key is the
* media type and the value describes it. The map _MUST_ only contain one
* entry.
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-content
* @see $content
*/
public const content = 'content';
/**
* A map containing the representations for the parameter. The key is the
* media type and the value describes it. The map _MUST_ only contain one
* entry.
*
* @var array<string, MediaType> $content
*
* @link https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-for-use-with-content
*/
#[Describe([
'cast' => [self::class, 'mapOf'],
'type' => MediaType::class,
'default' => []
])]
public array $content;
}