From a5a5b12d021b8152c0c4e2f65d59121c20b54023 Mon Sep 17 00:00:00 2001 From: jamo Date: Tue, 28 Jul 2026 13:14:04 +0100 Subject: [PATCH] Update Scalar to use JS API --- config/scribe.php | 2 ++ resources/views/external/scalar.blade.php | 13 +++++-------- src/Writing/ExternalHtmlWriter.php | 8 +++++++- src/Writing/Writer.php | 2 ++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/config/scribe.php b/config/scribe.php index 8fdbe8a8..f6b91f9f 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -85,6 +85,8 @@ 'external' => [ 'html_attributes' => [], + // Configuration specific for the scalar theme: https://scalar.com/products/api-references/configuration + 'scalar_config' => [], ], 'try_it_out' => [ diff --git a/resources/views/external/scalar.blade.php b/resources/views/external/scalar.blade.php index 062d3cfd..b7c70817 100644 --- a/resources/views/external/scalar.blade.php +++ b/resources/views/external/scalar.blade.php @@ -14,14 +14,11 @@ - +
+ + diff --git a/src/Writing/ExternalHtmlWriter.php b/src/Writing/ExternalHtmlWriter.php index b61f3b14..2e2d944b 100644 --- a/src/Writing/ExternalHtmlWriter.php +++ b/src/Writing/ExternalHtmlWriter.php @@ -12,11 +12,17 @@ class ExternalHtmlWriter extends HtmlWriter public function generate(array $groupedEndpoints, string $sourceFolder, string $destinationFolder) { $template = $this->config->get('theme'); + $metadata = $this->getMetadata(); + + $scalarConfig = $this->config->get('external.scalar_config', []); + $scalarConfig['url'] = $metadata['openapi_spec_url']; + $output = View::make("scribe::external.{$template}", [ - 'metadata' => $this->getMetadata(), + 'metadata' => $metadata, 'baseUrl' => $this->baseUrl, 'tryItOut' => $this->config->get('try_it_out'), 'htmlAttributes' => $this->config->get('external.html_attributes', []), + 'scalarConfig' => \json_encode($scalarConfig), ])->render(); if (! is_dir($destinationFolder)) { diff --git a/src/Writing/Writer.php b/src/Writing/Writer.php index d042e386..035e00e8 100644 --- a/src/Writing/Writer.php +++ b/src/Writing/Writer.php @@ -251,6 +251,8 @@ protected function performFinalTasksForLaravelType(): void $contents = str_replace('url="../docs/openapi.yaml"', 'url="{{ route("'.$this->paths->outputPath('openapi', '.').'") }}"', $contents); // With Elements theme, we'd have paths->outputPath('openapi', '.').'") }}"', $contents); + // Scribe JS API + $contents = str_replace('..\/docs\/openapi.yaml', '{{ route("'.$this->paths->outputPath('openapi', '.').'") }}', $contents); file_put_contents("{$this->laravelTypeOutputPath}/index.blade.php", $contents); }