forked from zircote/swagger-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parameter.php
299 lines (265 loc) · 8.53 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
<?php declare(strict_types=1);
/**
* @license Apache 2.0
*/
namespace OpenApi\Annotations;
use OpenApi\Generator;
/**
* Describes a single operation parameter.
*
* A unique parameter is defined by a combination of a name and location.
*
* @see [OAA Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object)
*
* @Annotation
*/
class Parameter extends AbstractAnnotation
{
/**
* The relative or absolute path to the endpoint.
*
* @see [Using refs](https://swagger.io/docs/specification/using-ref/)
*
* @var string|class-string|object
*/
public $ref = Generator::UNDEFINED;
/**
* The key into <code>Components::parameters</code> or <code>PathItem::parameters</code> array.
*
* @var string
*/
public $parameter = Generator::UNDEFINED;
/**
* The (case-sensitive) name of the parameter.
*
* If in is "path", the name field must correspond to the associated path segment from the path field in the Paths Object.
*
* 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 property.
*
* @var string
*/
public $name = Generator::UNDEFINED;
/**
* The location of the parameter.
*
* Possible values are "query", "header", "path" or "cookie".
*
* @var string
*/
public $in = Generator::UNDEFINED;
/**
* A brief description of the parameter.
*
* This could contain examples of use.
*
* CommonMark syntax may be used for rich text representation.
*
* @var string
*/
public $description = Generator::UNDEFINED;
/**
* Determines whether this parameter is mandatory.
*
* If the parameter location is "path", this property is required and its value must be true.
* Otherwise, the property may be included and its default value is false.
*
* @var bool
*/
public $required = Generator::UNDEFINED;
/**
* Specifies that a parameter is deprecated and should be transitioned out of usage.
*
* @var bool
*/
public $deprecated = Generator::UNDEFINED;
/**
* Sets the ability to pass empty-valued parameters.
*
* This is valid only for query parameters and allows sending a parameter with an empty value.
*
* Default value is false.
*
* If style is used, and if behavior is n/a (cannot be serialized), the value of allowEmptyValue shall be ignored.
*
* @var bool
*/
public $allowEmptyValue = Generator::UNDEFINED;
/**
* 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.
*
* @var string
*/
public $style = Generator::UNDEFINED;
/**
* 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 property has no effect.
*
* When style is form, the default value is true.
* For all other styles, the default value is false.
*
* @var bool
*/
public $explode = Generator::UNDEFINED;
/**
* Determines whether the parameter value should allow reserved characters, as defined by RFC3986 :/?#[]@!$&'()*+,;= to be included without percent-encoding.
*
* This property only applies to parameters with an in value of query.
*
* The default value is false.
*
* @var bool
*/
public $allowReserved = Generator::UNDEFINED;
/**
* The schema defining the type used for the parameter.
*
* @var Schema
*/
public $schema = Generator::UNDEFINED;
/**
* Example of the media type.
*
* The example should match the specified schema and encoding properties if present.
* The example object is mutually exclusive of the examples object.
* Furthermore, if referencing a schema which contains an example, the example value shall override the example provided by the schema.
* To represent examples of media types that cannot naturally be represented in JSON or YAML, a string value can contain the example with escaping where necessary.
*/
public $example = Generator::UNDEFINED;
/**
* Examples of the parameter.
*
* Each example should contain a value in the correct format as specified in the parameter encoding.
* The examples object is mutually exclusive of the example object.
* Furthermore, if referencing a schema which contains an example, the examples value shall override the example provided by the schema.
*
* @var array<Examples>
*/
public $examples = Generator::UNDEFINED;
/**
* 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<MediaType>|JsonContent|XmlContent|Attachable
*/
public $content = Generator::UNDEFINED;
/**
* Path-style parameters defined by RFC6570.
*
* @see [RFC6570](https://tools.ietf.org/html/rfc6570#section-3.2.7)
*/
public $matrix = Generator::UNDEFINED;
/**
* Label style parameters defined by RFC6570.
*
* @see [RFC6570](https://tools.ietf.org/html/rfc6570#section-3.2.5)
*/
public $label = Generator::UNDEFINED;
/**
* Form style parameters defined by RFC6570.
*
* This option replaces collectionFormat with a csv (when explode is false) or multi (when explode is true) value from OpenAPI 2.0.
*
* @see [RFC6570](https://tools.ietf.org/html/rfc6570#section-3.2.8)
*/
public $form = Generator::UNDEFINED;
/**
* Simple style parameters defined by RFC6570.
*
* This option replaces collectionFormat with a csv value from OpenAPI 2.0.
*
* @see [RFC6570](https://tools.ietf.org/html/rfc6570#section-3.2.2)
*
* @var array
*/
public $simple = Generator::UNDEFINED;
/**
* Space separated array values.
*
* This option replaces collectionFormat equal to ssv from OpenAPI 2.0.
*
* @var array
*/
public $spaceDelimited = Generator::UNDEFINED;
/**
* Pipe separated array values.
*
* This option replaces collectionFormat equal to pipes from OpenAPI 2.0.
*
* @var array
*/
public $pipeDelimited = Generator::UNDEFINED;
/**
* Provides a simple way of rendering nested objects using form parameters.
*/
public $deepObject = Generator::UNDEFINED;
/**
* @inheritdoc
*/
public static $_required = ['name', 'in'];
/**
* @inheritdoc
*/
public static $_types = [
'name' => 'string',
'in' => ['query', 'header', 'path', 'cookie'],
'description' => 'string',
'style' => ['matrix', 'label', 'form', 'simple', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
'required' => 'boolean',
];
/**
* @inheritdoc
*/
public static $_nested = [
Schema::class => 'schema',
Examples::class => ['examples', 'example'],
Attachable::class => ['attachables'],
];
/**
* @inheritdoc
*/
public static $_parents = [
Components::class,
PathItem::class,
Operation::class,
Get::class,
Post::class,
Put::class,
Delete::class,
Patch::class,
Head::class,
Options::class,
Trace::class,
];
/**
* @inheritdoc
*/
public function validate(array $stack = [], array $skip = [], string $ref = '', $context = null): bool
{
if (in_array($this, $skip, true)) {
return true;
}
$valid = parent::validate($stack, $skip, $ref, $context);
if (Generator::isDefault($this->ref)) {
if ($this->in === 'body') {
if (Generator::isDefault($this->schema)) {
$this->_context->logger->warning('Field "schema" is required when ' . $this->identity() . ' is in "' . $this->in . '" in ' . $this->_context);
$valid = false;
}
}
}
return $valid;
}
/**
* @inheritdoc
*/
public function identity(): string
{
return parent::_identity(['name', 'in']);
}
}