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; |
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 array |
66
|
|
|
* |
67
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oastags |
68
|
|
|
* |
69
|
|
|
* @todo need to implement the missing objects... |
70
|
|
|
*/ |
71
|
|
|
protected $tags; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var array |
75
|
|
|
* |
76
|
|
|
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-oasexternaldocs |
77
|
|
|
* |
78
|
|
|
* @todo need to implement the missing objects... |
79
|
|
|
*/ |
80
|
|
|
protected $externalDocs; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $openapi |
84
|
|
|
* @param Info $info |
85
|
|
|
*/ |
86
|
|
|
public function __construct(string $openapi, Info $info) |
87
|
|
|
{ |
88
|
|
|
$this->openapi = $openapi; |
89
|
|
|
$this->info = $info; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param Server ...$servers |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
public function addServer(Server ...$servers) : void |
98
|
|
|
{ |
99
|
|
|
foreach ($servers as $server) { |
100
|
|
|
$this->servers[] = $server; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param ComponentObjectInterface ...$objects |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
public function addComponentObject(ComponentObjectInterface ...$objects) : void |
110
|
|
|
{ |
111
|
|
|
foreach ($objects as $object) { |
112
|
|
|
$this->components[$object->getComponentName()][$object->getReferenceName()] = $object; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param SecurityRequirement ...$requirements |
118
|
|
|
* |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
public function addSecurityRequirement(SecurityRequirement ...$requirements) : void |
122
|
|
|
{ |
123
|
|
|
foreach ($requirements as $requirement) { |
124
|
|
|
$this->security[] = $requirement; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|