1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* It's free open-source software released under the MIT License. |
5
|
|
|
* |
6
|
|
|
* @author Anatoly Fenric <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2018, Anatoly Fenric |
8
|
|
|
* @license https://github.com/sunrise-php/http-router/blob/master/LICENSE |
9
|
|
|
* @link https://github.com/sunrise-php/http-router |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sunrise\Http\Router\Annotation\OpenApi; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @Annotation |
16
|
|
|
* |
17
|
|
|
* @Target({"ALL"}) |
18
|
|
|
* |
19
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object |
20
|
|
|
*/ |
21
|
|
|
final class Schema extends AbstractAnnotation implements SchemaInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $description = ''; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
public $type; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
public $format; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var mixed |
41
|
|
|
*/ |
42
|
|
|
public $default; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var mixed |
46
|
|
|
*/ |
47
|
|
|
public $example; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Sunrise\Http\Router\Annotation\OpenApi\SchemaInterface |
|
|
|
|
51
|
|
|
*/ |
52
|
|
|
public $items; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var array<Sunrise\Http\Router\Annotation\OpenApi\SchemaInterface> |
56
|
|
|
*/ |
57
|
|
|
public $properties = []; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
public $nullable = false; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var bool |
66
|
|
|
*/ |
67
|
|
|
public $readOnly = false; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var bool |
71
|
|
|
*/ |
72
|
|
|
public $writeOnly = false; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var bool |
76
|
|
|
*/ |
77
|
|
|
public $deprecated = false; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var bool |
81
|
|
|
*/ |
82
|
|
|
public $required = false; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritDoc} |
86
|
|
|
*/ |
87
|
|
|
public function toArray() : array |
88
|
|
|
{ |
89
|
|
|
$result = [ |
90
|
|
|
'description' => $this->description, |
91
|
|
|
'nullable' => $this->nullable, |
92
|
|
|
'readOnly' => $this->readOnly, |
93
|
|
|
'writeOnly' => $this->writeOnly, |
94
|
|
|
'deprecated' => $this->deprecated, |
95
|
|
|
'required' => $this->required, |
96
|
|
|
]; |
97
|
|
|
|
98
|
|
|
if (isset($this->type)) { |
99
|
|
|
$result['type'] = $this->type; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (isset($this->format)) { |
103
|
|
|
$result['format'] = $this->format; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if (isset($this->default)) { |
107
|
|
|
$result['default'] = $this->default; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if (isset($this->example)) { |
111
|
|
|
$result['example'] = $this->example; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if (isset($this->items)) { |
115
|
|
|
$result['items'] = $this->items->toArray(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
foreach ($this->properties as $key => $value) { |
119
|
|
|
$result['properties'][$key] = $value->toArray(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $result; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|