1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace gossi\swagger; |
4
|
|
|
|
5
|
|
|
use gossi\swagger\parts\TypePart; |
6
|
|
|
use gossi\swagger\parts\DescriptionPart; |
7
|
|
|
use gossi\swagger\parts\ItemsPart; |
8
|
|
|
use gossi\swagger\parts\ExtensionPart; |
9
|
|
|
use gossi\swagger\parts\ExternalDocsPart; |
10
|
|
|
use phootwork\collection\CollectionUtils; |
11
|
|
|
use gossi\swagger\parts\RefPart; |
12
|
|
|
use phootwork\collection\ArrayList; |
13
|
|
|
use gossi\swagger\collections\Definitions; |
14
|
|
|
use phootwork\lang\Arrayable; |
15
|
|
|
use phootwork\collection\Map; |
16
|
|
|
|
17
|
|
|
class Schema extends AbstractModel implements Arrayable |
18
|
|
|
{ |
19
|
|
|
use RefPart; |
20
|
|
|
use TypePart; |
21
|
|
|
use DescriptionPart; |
22
|
|
|
use ItemsPart; |
23
|
|
|
use ExternalDocsPart; |
24
|
|
|
use ExtensionPart; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
private $discriminator; |
28
|
|
|
|
29
|
|
|
/** @var bool */ |
30
|
|
|
private $readOnly = false; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
private $title; |
34
|
|
|
|
35
|
|
|
private $xml; |
|
|
|
|
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
private $example; |
39
|
|
|
|
40
|
|
|
/** @var ArrayList|bool */ |
41
|
|
|
private $required; |
42
|
|
|
|
43
|
|
|
/** @var Definitions */ |
44
|
|
|
private $properties; |
45
|
|
|
|
46
|
|
|
/** @var ArrayList */ |
47
|
|
|
private $allOf; |
48
|
|
|
|
49
|
|
|
/** @var Schema */ |
50
|
|
|
private $additionalProperties; |
51
|
|
|
|
52
|
9 |
|
public function __construct($contents = null) |
53
|
|
|
{ |
54
|
9 |
|
$this->parse($contents === null ? new Map() : $contents); |
55
|
9 |
|
} |
56
|
|
|
|
57
|
9 |
|
private function parse($contents = []) |
58
|
|
|
{ |
59
|
9 |
|
$data = CollectionUtils::toMap($contents); |
60
|
|
|
|
61
|
9 |
|
$this->title = $data->get('title'); |
62
|
9 |
|
$this->discriminator = $data->get('discriminator'); |
63
|
9 |
|
$this->readOnly = $data->has('readOnly') && $data->get('readOnly'); |
64
|
9 |
|
$this->example = $data->get('example'); |
65
|
9 |
|
$this->required = $data->get('required'); |
66
|
9 |
|
$this->properties = new Definitions($data->get('properties')); |
67
|
9 |
|
if ($data->has('additionalProperties')) { |
68
|
|
|
$this->additionalProperties = new self($data->get('additionalProperties')); |
69
|
9 |
|
} |
70
|
|
|
|
71
|
9 |
|
$this->allOf = new ArrayList(); |
72
|
9 |
|
if ($data->has('allOf')) { |
73
|
3 |
|
foreach ($data->get('allOf') as $schema) { |
74
|
3 |
|
$this->allOf->add(new self($schema)); |
75
|
3 |
|
} |
76
|
3 |
|
} |
77
|
|
|
|
78
|
|
|
// parts |
79
|
9 |
|
$this->parseRef($data); |
80
|
9 |
|
$this->parseType($data); |
81
|
9 |
|
$this->parseDescription($data); |
82
|
9 |
|
$this->parseItems($data); |
83
|
9 |
|
$this->parseExternalDocs($data); |
84
|
9 |
|
$this->parseExtensions($data); |
85
|
9 |
|
} |
86
|
|
|
|
87
|
6 |
|
public function toArray() |
88
|
|
|
{ |
89
|
6 |
|
return $this->export('title', 'discriminator', 'description', 'readOnly', 'example', |
90
|
6 |
|
'externalDocs', $this->getTypeExportFields(), 'items', 'required', |
91
|
6 |
|
'properties', 'additionalProperties', 'allOf'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return bool|array |
96
|
|
|
*/ |
97
|
|
|
public function getRequired() |
98
|
|
|
{ |
99
|
|
|
return $this->required; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param bool|array $required |
104
|
|
|
* |
105
|
|
|
* @return $this |
106
|
|
|
*/ |
107
|
|
|
public function setRequired($required) |
108
|
|
|
{ |
109
|
|
|
$this->required = $required; |
|
|
|
|
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getDiscriminator() |
118
|
|
|
{ |
119
|
|
|
return $this->discriminator; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $discriminator |
124
|
|
|
*/ |
125
|
|
|
public function setDiscriminator($discriminator) |
126
|
|
|
{ |
127
|
|
|
$this->discriminator = $discriminator; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return bool |
134
|
|
|
*/ |
135
|
|
|
public function isReadOnly() |
136
|
|
|
{ |
137
|
|
|
return $this->readOnly; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param bool $readOnly |
142
|
|
|
*/ |
143
|
|
|
public function setReadOnly($readOnly) |
144
|
|
|
{ |
145
|
|
|
$this->readOnly = $readOnly; |
146
|
|
|
|
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function getExample() |
154
|
|
|
{ |
155
|
|
|
return $this->example; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string $example |
160
|
|
|
*/ |
161
|
|
|
public function setExample($example) |
162
|
|
|
{ |
163
|
|
|
$this->example = $example; |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return string |
170
|
|
|
*/ |
171
|
|
|
public function getTitle() |
172
|
|
|
{ |
173
|
|
|
return $this->title; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param string $title |
178
|
|
|
* |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
|
|
public function setTitle($title) |
182
|
|
|
{ |
183
|
|
|
$this->title = $title; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return Definitions |
190
|
|
|
*/ |
191
|
|
|
public function getProperties() |
192
|
|
|
{ |
193
|
|
|
return $this->properties; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return ArrayList |
198
|
|
|
*/ |
199
|
|
|
public function getAllOf() |
200
|
|
|
{ |
201
|
|
|
return $this->allOf; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return Schema |
206
|
|
|
*/ |
207
|
|
|
public function getAdditionalProperties() |
208
|
|
|
{ |
209
|
|
|
if ($this->additionalProperties === null) { |
210
|
|
|
$this->additionalProperties = new self(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return $this->additionalProperties; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.