Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/scribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
13 changes: 5 additions & 8 deletions resources/views/external/scalar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
</head>
<body>

<script
id="api-reference"
@foreach($htmlAttributes as $attribute => $value)
{{-- Attributes specified first override later ones --}}
{!! $attribute !!}="{!! $value !!}"
@endforeach
data-url="{!! $metadata['openapi_spec_url'] !!}">
</script>
<div id="app"></div>

<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
<script>
Scalar.createApiReference('#app', {!! $scalarConfig !!})
</script>
</body>
</html>
8 changes: 7 additions & 1 deletion src/Writing/ExternalHtmlWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Writing/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <elements-api apiDescriptionUrl="../docs/openapi.yaml"
$contents = str_replace('Url="../docs/openapi.yaml"', 'Url="{{ route("'.$this->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);
}
Expand Down