Skip to content

Commit 723c49a

Browse files
committed
Scalar 支持多个url
1 parent 6cf3ed8 commit 723c49a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/Swagger/SwaggerUiController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ public function rapidoc(): PsrResponseInterface
5151
public function scalar(): PsrResponseInterface
5252
{
5353
// https://github.com/scalar/scalar
54+
$serverNameAll = array_reverse($this->swaggerOpenApi->serverNameAll);
55+
$urls = '';
56+
foreach ($serverNameAll as $serverName) {
57+
$url = $this->getSwaggerFileUrl($serverName);
58+
$urls .= "{url: '{$url}', title: '{$serverName} server'},";
59+
}
5460
$filePath = $this->docsWebPath . '/scalar.html';
5561
$contents = file_get_contents($filePath);
56-
$contents = str_replace('{{$url}}', BootAppRouteListener::$httpServerName . '.' . $this->swaggerConfig->getFormat(), $contents);
62+
$contents = str_replace('"{{$urls}}"', $urls, $contents);
63+
5764
return $this->response->withAddedHeader('content-type', 'text/html')->withBody(new SwooleStream($contents));
5865
}
5966

src/web/scalar.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
<!-- Initialize the Scalar API Reference -->
1818
<script>
1919
Scalar.createApiReference('#app', {
20-
// The URL of the OpenAPI/Swagger document
21-
url: '{{$url}}',
22-
// Avoid CORS issues
23-
// proxyUrl: '',
20+
sources: [
21+
"{{$urls}}"
22+
],
2423
})
2524
</script>
2625
</body>

0 commit comments

Comments
 (0)