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