-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathParameter.php
More file actions
341 lines (277 loc) · 7.25 KB
/
Parameter.php
File metadata and controls
341 lines (277 loc) · 7.25 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
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
<?php
declare(strict_types=1);
namespace GoldSpecDigital\ObjectOrientedOAS\Objects;
use GoldSpecDigital\ObjectOrientedOAS\Contracts\SchemaContract;
use GoldSpecDigital\ObjectOrientedOAS\Utilities\Arr;
/**
* @property string|null $name
* @property string|null $in
* @property string|null $description
* @property bool|null $required
* @property bool|null $deprecated
* @property bool|null $allowEmptyValue
* @property string|null $style
* @property bool|null $explode
* @property bool|null $allowReserved
* @property \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema|null $schema
* @property mixed|null $example
* @property \GoldSpecDigital\ObjectOrientedOAS\Objects\Example[]|null $examples
* @property \GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType[]|null $content
*/
class Parameter extends BaseObject
{
const IN_QUERY = 'query';
const IN_HEADER = 'header';
const IN_PATH = 'path';
const IN_COOKIE = 'cookie';
const STYLE_MATRIX = 'matrix';
const STYLE_LABEL = 'label';
const STYLE_FORM = 'form';
const STYLE_SIMPLE = 'simple';
const STYLE_SPACE_DELIMITED = 'spaceDelimited';
const STYLE_PIPE_DELIMITED = 'pipeDelimited';
const STYLE_DEEP_OBJECT = 'deepObject';
/**
* @var string|null
*/
protected $name;
/**
* @var string|null
*/
protected $in;
/**
* @var string|null
*/
protected $description;
/**
* @var bool|null
*/
protected $required;
/**
* @var bool|null
*/
protected $deprecated;
/**
* @var bool|null
*/
protected $allowEmptyValue;
/**
* @var string|null
*/
protected $style;
/**
* @var bool|null
*/
protected $explode;
/**
* @var string|null
*/
protected $allowReserved;
/**
* @var \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema|null
*/
protected $schema;
/**
* @var mixed|null
*/
protected $example;
/**
* @var \GoldSpecDigital\ObjectOrientedOAS\Objects\Example[]|null
*/
protected $examples;
/**
* @var \GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType[]|null
*/
protected $content;
/**
* @param string|null $objectId
* @return static
*/
public static function query(?string $objectId = null): self
{
return static::create($objectId)->in(static::IN_QUERY);
}
/**
* @param string|null $objectId
* @return static
*/
public static function header(?string $objectId = null): self
{
return static::create($objectId)->in(static::IN_HEADER);
}
/**
* @param string|null $objectId
* @return static
*/
public static function path(?string $objectId = null): self
{
return static::create($objectId)->in(static::IN_PATH);
}
/**
* @param string|null $objectId
* @return static
*/
public static function cookie(?string $objectId = null): self
{
return static::create($objectId)->in(static::IN_COOKIE);
}
/**
* @param string|null $name
* @return static
*/
public function name(?string $name): self
{
$instance = clone $this;
$instance->name = $name;
return $instance;
}
/**
* @param string|null $in
* @return static
*/
public function in(?string $in): self
{
$instance = clone $this;
$instance->in = $in;
return $instance;
}
/**
* @param string|null $description
* @return static
*/
public function description(?string $description): self
{
$instance = clone $this;
$instance->description = $description;
return $instance;
}
/**
* @param bool|null $required
* @return static
*/
public function required(?bool $required = true): self
{
$instance = clone $this;
$instance->required = $required;
return $instance;
}
/**
* @param bool|null $deprecated
* @return static
*/
public function deprecated(?bool $deprecated = true): self
{
$instance = clone $this;
$instance->deprecated = $deprecated;
return $instance;
}
/**
* @param bool|null $allowEmptyValue
* @return static
*/
public function allowEmptyValue(?bool $allowEmptyValue = true): self
{
$instance = clone $this;
$instance->allowEmptyValue = $allowEmptyValue;
return $instance;
}
/**
* @param string|null $style
* @return static
*/
public function style(?string $style): self
{
$instance = clone $this;
$instance->style = $style;
return $instance;
}
/**
* @param bool|null $explode
* @return static
*/
public function explode(?bool $explode = true): self
{
$instance = clone $this;
$instance->explode = $explode;
return $instance;
}
/**
* @param bool|null $allowReserved
* @return static
*/
public function allowReserved(?bool $allowReserved = true): self
{
$instance = clone $this;
$instance->allowReserved = $allowReserved;
return $instance;
}
/**
* @param \GoldSpecDigital\ObjectOrientedOAS\Contracts\SchemaContract|null $schema
* @return static
*/
public function schema(?SchemaContract $schema): self
{
$instance = clone $this;
$instance->schema = $schema;
return $instance;
}
/**
* @param mixed|null $example
* @return static
*/
public function example($example): self
{
$instance = clone $this;
$instance->example = $example;
return $instance;
}
/**
* @param \GoldSpecDigital\ObjectOrientedOAS\Objects\Example[]|null $examples
* @return static
*/
public function examples(Example ...$examples): self
{
$instance = clone $this;
$instance->examples = $examples ?: null;
return $instance;
}
/**
* @param \GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType[] $content
* @return static
*/
public function content(MediaType ...$content): self
{
$instance = clone $this;
$instance->content = $content ?: null;
return $instance;
}
/**
* @return array
*/
protected function generate(): array
{
$examples = [];
foreach ($this->examples ?? [] as $example) {
$examples[$example->objectId] = $example->toArray();
}
$content = [];
foreach ($this->content ?? [] as $contentItem) {
$content[$contentItem->mediaType] = $contentItem;
}
return Arr::filter([
'name' => $this->name,
'in' => $this->in,
'description' => $this->description,
'required' => $this->required,
'deprecated' => $this->deprecated,
'allowEmptyValue' => $this->allowEmptyValue,
'style' => $this->style,
'explode' => $this->explode,
'allowReserved' => $this->allowReserved,
'schema' => $this->schema,
'example' => $this->example,
'examples' => $examples ?: null,
'content' => $content ?: null,
]);
}
}