Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
WildEgo committed Mar 3, 2024
1 parent 51332b2 commit 12ca4f5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Support/Generator/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class OpenApi
/** @var Path[] */
public array $paths = [];

/** @var string[] */
public array $tags = [];

private ?Security $defaultSecurity = null;

public function __construct(string $version)
Expand Down Expand Up @@ -72,6 +75,23 @@ public function addPath(Path $path)
return $this;
}

/**
* @param string[] $tags
*/
public function tags(array $tags)
{
$this->tags = $tags;

return $this;
}

public function addTag(string $tag)
{
$this->tags[] = $tag;

return $this;
}

public function addServer(Server $server)
{
$this->servers[] = $server;
Expand Down Expand Up @@ -104,6 +124,12 @@ public function toArray()
$result['security'] = [$this->defaultSecurity->toArray()];
}

$tags = [];

if (count($this->tags)) {
$tags = $this->tags;
}

if (count($this->paths)) {
$paths = [];

Expand All @@ -115,6 +141,18 @@ public function toArray()
}

$result['paths'] = $paths;

$tags = array_merge(
$tags,
collect($paths)->pluck('*.tags')->flatten()->unique()->toArray(),
);
}

if (count($tags = array_filter($tags))) {
$keys = array_keys($tags);
$result['tags'] = array_map(fn ($tag) => [
'name' => $tag,
], $tags, $keys);
}

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

0 comments on commit 12ca4f5

Please sign in to comment.