Skip to content

Commit

Permalink
Allow passing of custom HTML attributes to external UIs
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Dec 29, 2023
1 parent 0342537 commit 411f184
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
4 changes: 4 additions & 0 deletions config/scribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
'middleware' => [],
],

'external' => [
'html_attributes' => []
],

'try_it_out' => [
// Add a Try It Out button to your endpoints so consumers can test endpoints right from their browser.
// Don't forget to enable CORS headers for your endpoints.
Expand Down
8 changes: 6 additions & 2 deletions resources/views/external/elements.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
<body>

<elements-api
@foreach($htmlAttributes as $attribute => $value)
{{-- Attributes specified first override later ones --}}
{!! $attribute !!}="{!! $value !!}"
@endforeach
apiDescriptionUrl="{!! $metadata['openapi_spec_url'] !!}"
router="hash"
layout="sidebar"
hideTryIt="{!! $metadata['try_it_out']['enabled'] == true ? '' : 'true'!!}"
logo ="{!! $metadata['logo'] ?: '' !!}"
hideTryIt="{!! ($tryItOut['enabled'] ?? true) ? '' : 'true'!!}"
logo="{!! $metadata['logo'] !!}"
/>

</body>
Expand Down
15 changes: 10 additions & 5 deletions resources/views/external/rapidoc.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
<script type="module" src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"></script>
</head>
<body>
<rapi-doc spec-url="{!! $metadata['openapi_spec_url'] !!}"
render-style="read"
allow-try="{!! $metadata['try_it_out']['enabled'] == true ? 'true' : 'false'!!}"
<rapi-doc
@foreach($htmlAttributes as $attribute => $value)
{{-- Attributes specified first override later ones --}}
{!! $attribute !!}="{!! $value !!}"
@endforeach
spec-url="{!! $metadata['openapi_spec_url'] !!}"
render-style="read"
allow-try="{!! ($tryItOut['enabled'] ?? true) ? 'true' : 'false'!!}"
>
@if($metadata['logo'] ?: '')
<img slot="logo" src="{!! $metadata['logo'] ?: '' !!}"/>
@if($metadata['logo'])
<img slot="logo" src="{!! $metadata['logo'] !!}"/>
@endif
</rapi-doc>
</body>
Expand Down
14 changes: 9 additions & 5 deletions resources/views/external/scalar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<html>
<head>
<title>{!! $metadata['title'] !!}</title>
<meta charset="utf-8" />
<meta charset="utf-8"/>
<meta
name="viewport"
content="width=device-width, initial-scale=1" />
name="viewport"
content="width=device-width, initial-scale=1"/>
<style>
body {
margin: 0;
Expand All @@ -15,8 +15,12 @@
<body>

<script
id="api-reference"
data-url="{!! $metadata['openapi_spec_url'] !!}">
id="api-reference"
@foreach($htmlAttributes as $attribute => $value)
{{-- Attributes specified first override later ones --}}
{!! $attribute !!}="{!! $value !!}"
@endforeach
data-url="{!! $metadata['openapi_spec_url'] !!}">
</script>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions src/Writing/ExternalHtmlWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function generate(array $groupedEndpoints, string $sourceFolder, string $
'metadata' => $this->getMetadata(),
'baseUrl' => $this->baseUrl,
'tryItOut' => $this->config->get('try_it_out'),
'htmlAttributes' => $this->config->get('external.html_attributes', []),
])->render();

if (!is_dir($destinationFolder)) {
Expand Down Expand Up @@ -44,4 +45,5 @@ public function getMetadata(): array
"openapi_spec_url" => $openApiSpecUrl ?? null,
];
}

}

0 comments on commit 411f184

Please sign in to comment.