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\OpenApi; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* OAS OpenAPI Object |
16
|
|
|
* |
17
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#openapi-object |
18
|
|
|
*/ |
19
|
|
|
class OpenApi extends AbstractObject |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
* |
25
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasversion |
26
|
|
|
*/ |
27
|
|
|
protected $openapi = '3.0.2'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Info |
31
|
|
|
* |
32
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasinfo |
33
|
|
|
*/ |
34
|
|
|
protected $info; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Server[] |
38
|
|
|
* |
39
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasservers |
40
|
|
|
*/ |
41
|
|
|
protected $servers; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array |
45
|
|
|
* |
46
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oaspaths |
47
|
|
|
*/ |
48
|
|
|
protected $paths; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array |
52
|
|
|
* |
53
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oascomponents |
54
|
|
|
*/ |
55
|
|
|
protected $components; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var SecurityRequirement[] |
59
|
|
|
* |
60
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oassecurity |
61
|
|
|
*/ |
62
|
|
|
protected $security; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var Tag[] |
66
|
|
|
* |
67
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oastags |
68
|
|
|
*/ |
69
|
|
|
protected $tags; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var ExternalDocumentation |
73
|
|
|
* |
74
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasexternaldocs |
75
|
|
|
*/ |
76
|
|
|
protected $externalDocs; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param Info $info |
80
|
|
|
*/ |
81
|
7 |
|
public function __construct(Info $info) |
82
|
|
|
{ |
83
|
7 |
|
$this->info = $info; |
84
|
7 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param Server ...$servers |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
1 |
|
public function addServer(Server ...$servers) : void |
92
|
|
|
{ |
93
|
1 |
|
foreach ($servers as $server) { |
94
|
1 |
|
$this->servers[] = $server; |
95
|
|
|
} |
96
|
1 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param ComponentObjectInterface ...$objects |
100
|
|
|
* |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
1 |
|
public function addComponentObject(ComponentObjectInterface ...$objects) : void |
104
|
|
|
{ |
105
|
1 |
|
foreach ($objects as $object) { |
106
|
1 |
|
$this->components[$object->getComponentName()][$object->getReferenceName()] = $object; |
107
|
|
|
} |
108
|
1 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param SecurityRequirement ...$requirements |
112
|
|
|
* |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
1 |
|
public function addSecurityRequirement(SecurityRequirement ...$requirements) : void |
116
|
|
|
{ |
117
|
1 |
|
foreach ($requirements as $requirement) { |
118
|
1 |
|
$this->security[] = $requirement; |
119
|
|
|
} |
120
|
1 |
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param Tag ...$tags |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
*/ |
127
|
1 |
|
public function addTag(Tag ...$tags) : void |
128
|
|
|
{ |
129
|
1 |
|
foreach ($tags as $tag) { |
130
|
1 |
|
$this->tags[] = $tag; |
131
|
|
|
} |
132
|
1 |
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param ExternalDocumentation $externalDocs |
136
|
|
|
* |
137
|
|
|
* @return void |
138
|
|
|
*/ |
139
|
1 |
|
public function setExternalDocs(ExternalDocumentation $externalDocs) : void |
140
|
|
|
{ |
141
|
1 |
|
$this->externalDocs = $externalDocs; |
142
|
1 |
|
} |
143
|
|
|
} |
144
|
|
|
|