Skip to content

Commit 12ca4f5

Browse files
committed
1 parent 51332b2 commit 12ca4f5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Support/Generator/OpenApi.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class OpenApi
1616
/** @var Path[] */
1717
public array $paths = [];
1818

19+
/** @var string[] */
20+
public array $tags = [];
21+
1922
private ?Security $defaultSecurity = null;
2023

2124
public function __construct(string $version)
@@ -72,6 +75,23 @@ public function addPath(Path $path)
7275
return $this;
7376
}
7477

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+
7595
public function addServer(Server $server)
7696
{
7797
$this->servers[] = $server;
@@ -104,6 +124,12 @@ public function toArray()
104124
$result['security'] = [$this->defaultSecurity->toArray()];
105125
}
106126

127+
$tags = [];
128+
129+
if (count($this->tags)) {
130+
$tags = $this->tags;
131+
}
132+
107133
if (count($this->paths)) {
108134
$paths = [];
109135

@@ -115,6 +141,18 @@ public function toArray()
115141
}
116142

117143
$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);
118156
}
119157

120158
if (count($serializedComponents = $this->components->toArray())) {

0 commit comments

Comments
 (0)