|
1
|
|
|
<?php |
|
2
|
|
|
namespace gossi\swagger\parts; |
|
3
|
|
|
|
|
4
|
|
|
use gossi\swagger\util\MergeHelper; |
|
5
|
|
|
use phootwork\collection\Map; |
|
6
|
|
|
|
|
7
|
|
|
trait TypePart { |
|
8
|
|
|
|
|
9
|
|
|
/** @var string */ |
|
10
|
|
|
private $type; |
|
11
|
|
|
|
|
12
|
|
|
/** @var string */ |
|
13
|
|
|
private $format; |
|
14
|
|
|
|
|
15
|
|
|
/** @var string */ |
|
16
|
|
|
private $collectionFormat; |
|
17
|
|
|
|
|
18
|
|
|
/** @var mixed */ |
|
19
|
|
|
private $default; |
|
20
|
|
|
|
|
21
|
|
|
/** @var float */ |
|
22
|
|
|
private $maximum; |
|
23
|
|
|
|
|
24
|
|
|
/** @var bool */ |
|
25
|
|
|
private $exclusiveMaximum; |
|
26
|
|
|
|
|
27
|
|
|
/** @var float */ |
|
28
|
|
|
private $minimum; |
|
29
|
|
|
|
|
30
|
|
|
/** @var bool */ |
|
31
|
|
|
private $exclusiveMinimum; |
|
32
|
|
|
|
|
33
|
|
|
/** @var int */ |
|
34
|
|
|
private $maxLength; |
|
35
|
|
|
|
|
36
|
|
|
/** @var int */ |
|
37
|
|
|
private $minLength; |
|
38
|
|
|
|
|
39
|
|
|
/** @var string */ |
|
40
|
|
|
private $pattern; |
|
41
|
|
|
|
|
42
|
|
|
/** @var int */ |
|
43
|
|
|
private $maxItems; |
|
44
|
|
|
|
|
45
|
|
|
/** @var int */ |
|
46
|
|
|
private $minItems; |
|
47
|
|
|
|
|
48
|
|
|
/** @var bool */ |
|
49
|
|
|
private $uniqueItems; |
|
50
|
|
|
|
|
51
|
|
|
/** @var mixed */ |
|
52
|
|
|
private $enum; |
|
53
|
|
|
|
|
54
|
|
|
/** @var float */ |
|
55
|
|
|
private $multipleOf; |
|
56
|
9 |
|
|
|
57
|
9 |
|
private function parseType(Map $data) { |
|
58
|
9 |
|
$this->type = $data->get('type'); |
|
59
|
9 |
|
$this->format = $data->get('format'); |
|
60
|
9 |
|
$this->collectionFormat = $data->get('collectionFormat'); |
|
61
|
9 |
|
$this->default = $data->get('default'); |
|
62
|
9 |
|
$this->maximum = $data->get('maximum'); |
|
63
|
9 |
|
$this->exclusiveMaximum = $data->get('exclusiveMaximum'); |
|
64
|
9 |
|
$this->minimum = $data->get('minimum'); |
|
65
|
9 |
|
$this->exclusiveMinimum = $data->get('exclusiveMinimum'); |
|
66
|
9 |
|
$this->maxLength = $data->get('maxLength'); |
|
67
|
9 |
|
$this->minLength = $data->get('minLength'); |
|
68
|
9 |
|
$this->pattern = $data->get('pattern'); |
|
69
|
9 |
|
$this->maxItems = $data->get('maxItems'); |
|
70
|
9 |
|
$this->minItems = $data->get('minItems'); |
|
71
|
9 |
|
$this->uniqueItems = $data->get('uniqueItems'); |
|
72
|
9 |
|
$this->enum = $data->get('enum'); |
|
73
|
9 |
|
$this->multipleOf = $data->get('multipleOf'); |
|
74
|
|
|
} |
|
75
|
9 |
|
|
|
76
|
9 |
|
private function mergeType(static $model, $overwrite = false) { |
|
|
|
|
|
|
77
|
9 |
|
MergeHelper::mergeFields($this->type, $model->type, $overwrite); |
|
78
|
9 |
|
MergeHelper::mergeFields($this->format, $model->format, $overwrite); |
|
79
|
9 |
|
MergeHelper::mergeFields($this->collectionFormat, $model->collectionFormat, $overwrite); |
|
80
|
|
|
MergeHelper::mergeFields($this->default, $model->default, $overwrite); |
|
81
|
|
|
MergeHelper::mergeFields($this->maximum, $model->maximum, $overwrite); |
|
82
|
|
|
MergeHelper::mergeFields($this->exclusiveMaximum, $model->exclusiveMaximum, $overwrite); |
|
83
|
|
|
MergeHelper::mergeFields($this->minimum, $model->minimum, $overwrite); |
|
84
|
|
|
MergeHelper::mergeFields($this->exclusiveMinimum, $model->exclusiveMinimum, $overwrite); |
|
85
|
|
|
MergeHelper::mergeFields($this->maxLength, $model->maxLength, $overwrite); |
|
86
|
1 |
|
MergeHelper::mergeFields($this->minLength, $model->minLength, $overwrite); |
|
87
|
1 |
|
MergeHelper::mergeFields($this->pattern, $model->pattern, $overwrite); |
|
88
|
|
|
MergeHelper::mergeFields($this->maxItems, $model->maxItems, $overwrite); |
|
89
|
|
|
MergeHelper::mergeFields($this->minItems, $model->minItems, $overwrite); |
|
90
|
|
|
MergeHelper::mergeFields($this->uniqueItems, $model->uniqueItems, $overwrite); |
|
91
|
|
|
MergeHelper::mergeFields($this->enum, $model->enum, $overwrite); |
|
92
|
|
|
MergeHelper::mergeFields($this->multipleOf, $model->multipleOf, $overwrite); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
private function getTypeExportFields() { |
|
96
|
|
|
return ['type', 'format', 'collectionFormat', 'default', 'maximum', 'exclusiveMaximum', |
|
97
|
|
|
'minimum', 'exclusiveMinimum', 'maxLength', 'minLength', 'pattern', 'maxItems', |
|
98
|
|
|
'minItems', 'uniqueItems', 'enum', 'multipleOf' |
|
99
|
|
|
]; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getType() { |
|
107
|
|
|
return $this->type; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $type |
|
113
|
|
|
* @return $this |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setType($type) { |
|
116
|
|
|
$this->type = $type; |
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getFormat() { |
|
125
|
|
|
return $this->format; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Sets the extending format for the type |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $format |
|
132
|
|
|
* @return $this |
|
133
|
|
|
*/ |
|
134
|
|
|
public function setFormat($format) { |
|
135
|
|
|
$this->format = $format; |
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getCollectionFormat() { |
|
144
|
|
|
return $this->collectionFormat; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Determines the format of the array if type array is used. Possible values are: |
|
149
|
|
|
* |
|
150
|
|
|
* - `csv` - comma separated values `foo,bar`. |
|
151
|
|
|
* - `ssv` - space separated values `foo bar`. |
|
152
|
|
|
* - `tsv` - tab separated values `foo\tbar`. |
|
153
|
|
|
* - `pipes` - pipe separated values `foo|bar`. |
|
154
|
|
|
* - `multi` - corresponds to multiple parameter instances instead of multiple values for a |
|
155
|
|
|
* single instance `foo=bar&foo=baz`. This is valid only for parameters in "query" or "formData". |
|
156
|
|
|
* |
|
157
|
|
|
* Default value is `csv`. |
|
158
|
|
|
* |
|
159
|
|
|
* |
|
160
|
|
|
* @param string $collectionFormat |
|
161
|
|
|
* @return $this |
|
162
|
|
|
*/ |
|
163
|
|
|
public function setCollectionFormat($collectionFormat) { |
|
164
|
|
|
$this->collectionFormat = $collectionFormat; |
|
165
|
|
|
return $this; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* |
|
170
|
|
|
* @return mixed |
|
171
|
|
|
*/ |
|
172
|
|
|
public function getDefault() { |
|
173
|
|
|
return $this->default; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* |
|
178
|
|
|
* @param mixed $default |
|
179
|
|
|
* @return $this |
|
180
|
|
|
*/ |
|
181
|
|
|
public function setDefault($default) { |
|
182
|
|
|
$this->default = $default; |
|
183
|
|
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* |
|
188
|
|
|
* @return float |
|
189
|
|
|
*/ |
|
190
|
|
|
public function getMaximum() { |
|
191
|
|
|
return $this->maximum; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* |
|
196
|
|
|
* @param float $maximum |
|
197
|
|
|
* @return $this |
|
198
|
|
|
*/ |
|
199
|
|
|
public function setMaximum($maximum) { |
|
200
|
|
|
$this->maximum = $maximum; |
|
201
|
|
|
return $this; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* |
|
206
|
|
|
* @return bool |
|
207
|
|
|
*/ |
|
208
|
|
|
public function isExclusiveMaximum() { |
|
209
|
|
|
return null !== $this->exclusiveMaximum ? $this->exclusiveMaximum : false; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* |
|
214
|
|
|
* @param bool $exclusiveMaximum |
|
215
|
|
|
* @return $this |
|
216
|
|
|
*/ |
|
217
|
|
|
public function setExclusiveMaximum($exclusiveMaximum) { |
|
218
|
|
|
$this->exclusiveMaximum = $exclusiveMaximum; |
|
219
|
|
|
return $this; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* |
|
224
|
|
|
* @return float |
|
225
|
|
|
*/ |
|
226
|
|
|
public function getMinimum() { |
|
227
|
|
|
return $this->minimum; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* |
|
232
|
|
|
* @param float $minimum |
|
233
|
|
|
* @return $this |
|
234
|
|
|
*/ |
|
235
|
|
|
public function setMinimum($minimum) { |
|
236
|
|
|
$this->minimum = $minimum; |
|
237
|
|
|
return $this; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* |
|
242
|
|
|
* @return bool |
|
243
|
|
|
*/ |
|
244
|
|
|
public function isExclusiveMinimum() { |
|
245
|
|
|
return null !== $this->exclusiveMinimum ? $this->exclusiveMinimum : false; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* |
|
250
|
|
|
* @param bool $exclusiveMinimum |
|
251
|
|
|
* @return $this |
|
252
|
|
|
*/ |
|
253
|
|
|
public function setExclusiveMinimum($exclusiveMinimum) { |
|
254
|
|
|
$this->exclusiveMinimum = $exclusiveMinimum; |
|
255
|
|
|
return $this; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* |
|
260
|
|
|
* @return int |
|
261
|
|
|
*/ |
|
262
|
|
|
public function getMaxLength() { |
|
263
|
|
|
return $this->maxLength; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* |
|
268
|
|
|
* @param int $maxLength |
|
269
|
|
|
* @return $this |
|
270
|
|
|
*/ |
|
271
|
|
|
public function setMaxLength($maxLength) { |
|
272
|
|
|
$this->maxLength = $maxLength; |
|
273
|
|
|
return $this; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* |
|
278
|
|
|
* @return int |
|
279
|
|
|
*/ |
|
280
|
|
|
public function getMinLength() { |
|
281
|
|
|
return $this->minLength; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* |
|
286
|
|
|
* @param int $minLength |
|
287
|
|
|
* @return $this |
|
288
|
|
|
*/ |
|
289
|
|
|
public function setMinLength($minLength) { |
|
290
|
|
|
$this->minLength = $minLength; |
|
291
|
|
|
return $this; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* |
|
296
|
|
|
* @return string |
|
297
|
|
|
*/ |
|
298
|
|
|
public function getPattern() { |
|
299
|
|
|
return $this->pattern; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* |
|
304
|
|
|
* @param string $pattern |
|
305
|
|
|
* @return $thi |
|
306
|
|
|
*/ |
|
307
|
|
|
public function setPattern($pattern) { |
|
308
|
|
|
$this->pattern = $pattern; |
|
309
|
|
|
return $this; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* |
|
314
|
|
|
* @return int |
|
315
|
|
|
*/ |
|
316
|
|
|
public function getMaxItems() { |
|
317
|
|
|
return $this->maxItems; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* |
|
322
|
|
|
* @param int $maxItems |
|
323
|
|
|
* @return $this |
|
324
|
|
|
*/ |
|
325
|
|
|
public function setMaxItems($maxItems) { |
|
326
|
|
|
$this->maxItems = $maxItems; |
|
327
|
|
|
return $this; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* |
|
332
|
|
|
* @return int |
|
333
|
|
|
*/ |
|
334
|
|
|
public function getMinItems() { |
|
335
|
|
|
return $this->minItems; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* |
|
340
|
|
|
* @param int $minItems |
|
341
|
|
|
* @return $this |
|
342
|
|
|
*/ |
|
343
|
|
|
public function setMinItems($minItems) { |
|
344
|
|
|
$this->minItems = $minItems; |
|
345
|
|
|
return $this; |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* |
|
350
|
|
|
* @return bool |
|
351
|
|
|
*/ |
|
352
|
|
|
public function hasUniqueItems() { |
|
353
|
|
|
return $this->uniqueItems; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* |
|
358
|
|
|
* @param bool $uniqueItems |
|
359
|
|
|
* @return $this |
|
360
|
|
|
*/ |
|
361
|
|
|
public function setUniqueItems($uniqueItems) { |
|
362
|
|
|
$this->uniqueItems = $uniqueItems; |
|
363
|
|
|
return $this; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* |
|
368
|
|
|
* @return mixed |
|
369
|
|
|
*/ |
|
370
|
|
|
public function getEnum() { |
|
371
|
|
|
return $this->enum; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* |
|
376
|
|
|
* @param mixed $enum |
|
377
|
|
|
* @return $this |
|
378
|
|
|
*/ |
|
379
|
|
|
public function setEnum($enum) { |
|
380
|
|
|
$this->enum = $enum; |
|
381
|
|
|
return $this; |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* |
|
386
|
|
|
* @return float |
|
387
|
|
|
*/ |
|
388
|
|
|
public function getMultipleOf() { |
|
389
|
|
|
return $this->multipleOf; |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* |
|
394
|
|
|
* @param float $multipleOf |
|
395
|
|
|
* @return $this |
|
396
|
|
|
*/ |
|
397
|
|
|
public function setMultipleOf($multipleOf) { |
|
398
|
|
|
$this->multipleOf = $multipleOf; |
|
399
|
|
|
return $this; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
} |
|
403
|
|
|
|