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