Skip to content

Commit 14f2726

Browse files
committed
optimize code
1 parent 8f6da17 commit 14f2726

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Listener/AfterDtoStartListener.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function __construct(
2626
private SwaggerComponents $swaggerComponents,
2727
private SwaggerConfig $swaggerConfig,
2828
private DtoConfig $dtoConfig,
29-
) {}
29+
) {
30+
}
3031

3132
public function listen(): array
3233
{
@@ -49,11 +50,13 @@ public function process(object $event): void
4950
if (! $this->swaggerConfig->getOutputDir()) {
5051
return;
5152
}
53+
54+
$this->swaggerOpenApi->init($server['name']);
55+
5256
if ($this->dtoConfig->isScanCacheable()) {
5357
return;
5458
}
5559

56-
$this->swaggerOpenApi->init();
5760
/** @var SwaggerPaths $swagger */
5861
$swagger = make(SwaggerPaths::class, [$server['name']]);
5962
foreach ($router->getData() ?? [] as $routeData) {

src/Swagger/SwaggerOpenApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
) {
3131
}
3232

33-
public function init(): void
33+
public function init(string $serverName): void
3434
{
3535
$this->openApi = new OpenApi();
3636
$this->openApi->paths = [];
@@ -45,6 +45,7 @@ public function init(): void
4545
$this->setComponentsSecuritySchemes();
4646
$this->setSecurity();
4747
$this->setExternalDocs();
48+
$this->serverNameAll[] = $serverName;
4849
}
4950

5051
public function clean(): void
@@ -139,7 +140,6 @@ public function save(string $serverName): void
139140
}
140141
$outputFile = $outputDir . '/' . $serverName . '.' . $this->swaggerConfig->getFormat();
141142
$this->openApi->saveAs($outputFile);
142-
$this->serverNameAll[] = $serverName;
143143
}
144144

145145
protected function setInfo(): void

0 commit comments

Comments
 (0)