File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ class OpenApi
16
16
/** @var Path[] */
17
17
public array $ paths = [];
18
18
19
+ /** @var string[] */
20
+ public array $ tags = [];
21
+
19
22
private ?Security $ defaultSecurity = null ;
20
23
21
24
public function __construct (string $ version )
@@ -72,6 +75,23 @@ public function addPath(Path $path)
72
75
return $ this ;
73
76
}
74
77
78
+ /**
79
+ * @param string[] $tags
80
+ */
81
+ public function tags (array $ tags )
82
+ {
83
+ $ this ->tags = $ tags ;
84
+
85
+ return $ this ;
86
+ }
87
+
88
+ public function addTag (string $ tag )
89
+ {
90
+ $ this ->tags [] = $ tag ;
91
+
92
+ return $ this ;
93
+ }
94
+
75
95
public function addServer (Server $ server )
76
96
{
77
97
$ this ->servers [] = $ server ;
@@ -104,6 +124,12 @@ public function toArray()
104
124
$ result ['security ' ] = [$ this ->defaultSecurity ->toArray ()];
105
125
}
106
126
127
+ $ tags = [];
128
+
129
+ if (count ($ this ->tags )) {
130
+ $ tags = $ this ->tags ;
131
+ }
132
+
107
133
if (count ($ this ->paths )) {
108
134
$ paths = [];
109
135
@@ -115,6 +141,18 @@ public function toArray()
115
141
}
116
142
117
143
$ result ['paths ' ] = $ paths ;
144
+
145
+ $ tags = array_merge (
146
+ $ tags ,
147
+ collect ($ paths )->pluck ('*.tags ' )->flatten ()->unique ()->toArray (),
148
+ );
149
+ }
150
+
151
+ if (count ($ tags = array_filter ($ tags ))) {
152
+ $ keys = array_keys ($ tags );
153
+ $ result ['tags ' ] = array_map (fn ($ tag ) => [
154
+ 'name ' => $ tag ,
155
+ ], $ tags , $ keys );
118
156
}
119
157
120
158
if (count ($ serializedComponents = $ this ->components ->toArray ())) {
You can’t perform that action at this time.
0 commit comments