-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoding.php
More file actions
208 lines (193 loc) · 8.95 KB
/
Encoding.php
File metadata and controls
208 lines (193 loc) · 8.95 KB
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
<?php
namespace Zerotoprod\DataModelOpenapi30;
use Zerotoprod\DataModel\Describe;
use Zerotoprod\DataModelOpenapi30\Helpers\DataModel;
/**
* A single encoding definition applied to a single schema property.
* See Appendix B for a discussion of converting values of various
* types to string representations.
*
* Properties are correlated with `multipart` parts using the name
* parameter of `Content-Disposition: form-data`, and with
* `application/x-www-form-urlencoded` using the query
* string parameter names. In both cases, their order
* is implementation-defined.
*
* See Appendix E for a detailed examination of percent-encoding concerns for form media types.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#encoding-object
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
class Encoding
{
use DataModel;
/**
* The `Content-Type` for encoding a specific property. The value is a
* comma-separated list, each element of which is either a specific
* media type (e.g. `image/png`) or a wildcard media type (e.g.
* `image/*`). Default value depends on the property type as
* shown in the table below.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-0
* @see $contentType
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
public const contentType = 'contentType';
/**
* The `Content-Type` for encoding a specific property. The value is a
* comma-separated list, each element of which is either a specific
* media type (e.g. `image/png`) or a wildcard media type (e.g.
* `image/*`). Default value depends on the property type as
* shown in the table below.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-0
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
#[Describe(['nullable'])]
public ?string $contentType;
/**
* A map allowing additional information to be provided as headers.
* `Content-Type` is described separately and _SHALL_ be ignored
* in this section. This field _SHALL_ be ignored if the request
* body media type is not a multipart.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-0
* @see $headers
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
public const headers = 'headers';
/**
* A map allowing additional information to be provided as headers.
* `Content-Type` is described separately and _SHALL_ be ignored
* in this section. This field _SHALL_ be ignored if the request
* body media type is not a multipart.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-0
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
#[Describe(['cast' => [self::class, 'headers']])]
public null|Header|Reference $headers;
/**
* A map allowing additional information to be provided as headers.
* `Content-Type` is described separately and _SHALL_ be ignored
* in this section. This field _SHALL_ be ignored if the request
* body media type is not a multipart.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-0
* @see $headers
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
public static function headers($value, array $context): Header|Reference|null
{
if (!isset($context[self::headers])) {
return null;
}
return isset($value[Reference::ref])
? Reference::from($value)
: Header::from($value);
}
/**
* Describes how a specific property value will be serialized depending on its
* type. See Parameter Object for details on the `style` field. The behavior
* follows the same values as `query` parameters, including default values.
* Note that the initial `?` used in query strings is not used in
* `application/x-www-form-urlencoded` message bodies, and
* _MUST_ be removed (if using an RFC6570 implementation)
* or simply not added (if constructing the string
* manually). This field _SHALL_ be ignored if
* the request body media type is not
* `application/x-www-form-urlencoded`.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-0
* @see $style
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
public const style = 'style';
/**
* Describes how a specific property value will be serialized depending on its
* type. See Parameter Object for details on the `style` field. The behavior
* follows the same values as `query` parameters, including default values.
* Note that the initial `?` used in query strings is not used in
* `application/x-www-form-urlencoded` message bodies, and
* _MUST_ be removed (if using an RFC6570 implementation)
* or simply not added (if constructing the string
* manually). This field _SHALL_ be ignored if
* the request body media type is not
* `application/x-www-form-urlencoded`.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-0
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
#[Describe(['nullable'])]
public ?string $style;
/**
* When this is true, property 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 properties 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. This field
* _SHALL_ be ignored if the request body media type is not
* `application/x-www-form-urlencoded`.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-1
* @see $explode
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
public const explode = 'explode';
/**
* When this is true, property 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 properties 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. This field
* _SHALL_ be ignored if the request body media type is not
* `application/x-www-form-urlencoded`.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-1
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
#[Describe(['default' => false])]
public bool $explode;
/**
* 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. The default
* value is `false`. This field _SHALL_ be
* ignored if the request body media type is
* not `application/x-www-form-urlencoded`.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-1
* @see $allowReserved
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
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. The default
* value is `false`. This field _SHALL_ be
* ignored if the request body media type is
* not `application/x-www-form-urlencoded`.
*
* @see https://spec.openapis.org/oas/v3.0.4.html#common-fixed-fields-1
* @link https://github.com/zero-to-prod/data-model-openapi30
*/
#[Describe(['default' => false])]
public bool $allowReserved;
}