235 lines
12 KiB
PHP
235 lines
12 KiB
PHP
<!doctype html>
|
|
<html lang="en" data-theme="{{ $config->renderer()->get('theme', 'light') }}">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
<meta name="color-scheme" content="{{ $config->renderer()->get('theme', 'light') }}">
|
|
<title>{{ $config->get('ui.title') ?? config('app.name') . ' - API Docs' }}</title>
|
|
|
|
<script src="https://unpkg.com/@stoplight/elements@8.4.2/web-components.min.js"></script>
|
|
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements@8.4.2/styles.min.css">
|
|
<link rel="shortcut icon" href="{{ asset('assets/images/logo-untan.png') }}">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap" rel="stylesheet">
|
|
|
|
@include('scramble::dev-tools', ['renderer' => 'elements'])
|
|
|
|
<script>
|
|
const originalFetch = window.fetch;
|
|
|
|
// intercept TryIt requests and add the XSRF-TOKEN header,
|
|
// which is necessary for Sanctum cookie-based authentication to work correctly
|
|
window.fetch = (url, options) => {
|
|
const CSRF_TOKEN_COOKIE_KEY = "XSRF-TOKEN";
|
|
const CSRF_TOKEN_HEADER_KEY = "X-XSRF-TOKEN";
|
|
const getCookieValue = (key) => {
|
|
const cookie = document.cookie.split(';').find((cookie) => cookie.trim().startsWith(key));
|
|
return cookie?.split("=")[1];
|
|
};
|
|
|
|
const updateFetchHeaders = (
|
|
headers,
|
|
headerKey,
|
|
headerValue,
|
|
) => {
|
|
if (headers instanceof Headers) {
|
|
headers.set(headerKey, headerValue);
|
|
} else if (Array.isArray(headers)) {
|
|
headers.push([headerKey, headerValue]);
|
|
} else if (headers) {
|
|
headers[headerKey] = headerValue;
|
|
}
|
|
};
|
|
const csrfToken = getCookieValue(CSRF_TOKEN_COOKIE_KEY);
|
|
if (csrfToken) {
|
|
const { headers = new Headers() } = options || {};
|
|
updateFetchHeaders(headers, CSRF_TOKEN_HEADER_KEY, decodeURIComponent(csrfToken));
|
|
return originalFetch(url, {
|
|
...options,
|
|
headers,
|
|
});
|
|
}
|
|
|
|
return originalFetch(url, options);
|
|
};
|
|
</script>
|
|
|
|
<style>
|
|
:root { --verif-primary: #0166d2; --verif-bg: #fafbfe; --verif-topbar: 70px; }
|
|
html, body { margin:0; height:100%; font-family: "Inter", sans-serif; }
|
|
elements-api { display: block; height: 100%; }
|
|
elements-api, elements-api * { font-family: "Inter", sans-serif; }
|
|
elements-api { --color-primary: var(--verif-primary); --color-primary-light: #3d8ce0; --color-primary-dark: #014f9f; --color-primary-darker: #013a75; }
|
|
.verif-topbar { height: var(--verif-topbar); box-sizing: border-box; display: flex; align-items: center; gap: 10px; padding: 0 24px; background: #fff; border-bottom: 1px solid #e3e6ec; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
|
|
.verif-topbar img { height: 36px; }
|
|
.verif-topbar span { font-size: 20px; font-weight: 600; color: #000; }
|
|
.verif-topbar small { font-size: 13px; color: #6c757d; margin-left: 6px; }
|
|
.verif-content { height: calc(100vh - var(--verif-topbar)); overflow-y: auto; }
|
|
body { background-color: var(--verif-bg); }
|
|
/* Layout mengikuti aplikasi Verifikator: sidebar kiri + topbar */
|
|
:root { --verif-side: 260px; }
|
|
.verif-side { position: fixed; top: 0; bottom: 0; left: 0; width: var(--verif-side); background: #fff; border-right: 1px solid #e3e6ec; display: flex; flex-direction: column; z-index: 10; }
|
|
.verif-logo { height: var(--verif-topbar); display: flex; align-items: center; justify-content: center; gap: 8px; flex-shrink: 0; text-decoration: none; }
|
|
.verif-logo img { height: 36px; margin-bottom: 5px; }
|
|
.verif-logo span { font-size: 20px; color: #000; }
|
|
.verif-nav { flex: 1; overflow-y: auto; padding: 0 0 24px; }
|
|
.verif-nav-title { padding: 12px 20px 6px; font-size: 12px; letter-spacing: .05rem; text-transform: uppercase; font-weight: 700; color: #000; }
|
|
.verif-nav a { display: flex; align-items: center; gap: 8px; margin: 2px 8px; padding: 8px 12px; border-radius: 8px; font-size: 14px; color: #000; text-decoration: none; }
|
|
.verif-nav a:hover { color: var(--verif-primary); }
|
|
.verif-nav a.active { background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #1d4ed8 100%); color: #fff; }
|
|
.verif-nav a .m { flex-shrink: 0; min-width: 34px; text-align: center; font-size: 10px; font-weight: 700; text-transform: uppercase; border-radius: 4px; padding: 1px 4px; background: #e8f1fb; color: var(--verif-primary); }
|
|
.verif-nav a.active .m { background: rgba(255,255,255,.2); color: #fff; }
|
|
.verif-nav a .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
/* Warna metode HTTP */
|
|
.verif-nav a .m { --mc: #0166d2; background: color-mix(in srgb, var(--mc) 14%, #fff); color: var(--mc); }
|
|
.verif-nav a .m-get { --mc: #0acf97; }
|
|
.verif-nav a .m-post { --mc: #0166d2; }
|
|
.verif-nav a .m-put { --mc: #e6a700; }
|
|
.verif-nav a .m-patch { --mc: #fd7e14; }
|
|
.verif-nav a .m-delete { --mc: #fa5c7c; }
|
|
.verif-nav a.active .m { background: rgba(255,255,255,.22); color: #fff; }
|
|
/* Scrollbar tipis seperti simplebar di aplikasi */
|
|
* { scrollbar-width: thin; scrollbar-color: rgba(115, 124, 138, .45) transparent; }
|
|
*::-webkit-scrollbar { width: 6px; height: 6px; }
|
|
*::-webkit-scrollbar-track { background: transparent; }
|
|
*::-webkit-scrollbar-thumb { background: rgba(115, 124, 138, .45); border-radius: 6px; }
|
|
*::-webkit-scrollbar-thumb:hover { background: rgba(115, 124, 138, .7); }
|
|
.verif-nav { padding-right: 2px; }
|
|
.verif-main { margin-left: var(--verif-side); height: 100vh; display: flex; flex-direction: column; }
|
|
/* Area konten: lebar penuh, rapi */
|
|
.sl-elements-api > div.sl-overflow-y-auto { padding-left: 32px !important; padding-right: 32px !important; background: var(--verif-bg) !important; }
|
|
.sl-elements-api > div.sl-overflow-y-auto > div { max-width: none !important; width: 100%; padding-top: 32px !important; padding-bottom: 48px !important; }
|
|
[data-testid="two-column-right"] { width: 52% !important; margin-left: 40px !important; }
|
|
[data-testid="two-column-right"] > * { border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
|
|
[data-testid="two-column-left"] { min-width: 0; }
|
|
.sl-elements-api h1 { font-size: 30px !important; font-weight: 600 !important; }
|
|
.sl-elements-api h2 { font-size: 22px !important; font-weight: 600 !important; }
|
|
.sl-elements-api h3 { font-size: 17px !important; font-weight: 600 !important; }
|
|
/* Contoh respons/request: lebar penuh, tanpa terpotong */
|
|
[data-testid="two-column-right"] pre, [data-testid="two-column-right"] code { font-size: 13px; }
|
|
[data-testid="two-column-right"] .sl-code-viewer, [data-testid="two-column-right"] .sl-panel__content { max-height: none !important; }
|
|
.verif-topbar { justify-content: flex-start; flex-shrink: 0; }
|
|
.verif-content { flex: 1; min-height: 0; height: auto !important; }
|
|
/* Sembunyikan sidebar bawaan Elements pada layar lebar (diganti sidebar di atas) */
|
|
.sl-elements-api > div:first-child:has([style*="min-width: 300px"]) { display: none !important; }
|
|
@media (max-width: 991px) {
|
|
.verif-side { display: none; }
|
|
.verif-main { margin-left: 0; }
|
|
}
|
|
/* issues about the dark theme of stoplight/mosaic-code-viewer using web component:
|
|
* https://github.com/stoplightio/elements/issues/2188#issuecomment-1485461965
|
|
*/
|
|
[data-theme="dark"] .token.property {
|
|
color: rgb(128, 203, 196) !important;
|
|
}
|
|
[data-theme="dark"] .token.operator {
|
|
color: rgb(255, 123, 114) !important;
|
|
}
|
|
[data-theme="dark"] .token.number {
|
|
color: rgb(247, 140, 108) !important;
|
|
}
|
|
[data-theme="dark"] .token.string {
|
|
color: rgb(165, 214, 255) !important;
|
|
}
|
|
[data-theme="dark"] .token.boolean {
|
|
color: rgb(121, 192, 255) !important;
|
|
}
|
|
[data-theme="dark"] .token.punctuation {
|
|
color: #dbdbdb !important;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body style="height: 100vh; overflow-y: hidden">
|
|
@php
|
|
$verifMethods = ['get', 'post', 'put', 'patch', 'delete'];
|
|
$verifGroups = [];
|
|
foreach (($spec['paths'] ?? []) as $verifPath => $verifItem) {
|
|
foreach ($verifItem as $verifMethod => $verifOp) {
|
|
if (! in_array($verifMethod, $verifMethods, true) || empty($verifOp['operationId'])) {
|
|
continue;
|
|
}
|
|
$verifGroups[$verifOp['tags'][0] ?? 'Lainnya'][] = [
|
|
'id' => $verifOp['operationId'],
|
|
'method' => $verifMethod,
|
|
'label' => $verifOp['summary'] ?? $verifPath,
|
|
'path' => $verifPath,
|
|
];
|
|
}
|
|
}
|
|
@endphp
|
|
<aside class="verif-side">
|
|
<a class="verif-logo" href="#/">
|
|
<img src="{{ asset('assets/images/logo-untan.png') }}" alt="UNTAN">
|
|
<span>{{ config('app.name') }}</span>
|
|
</a>
|
|
<nav class="verif-nav" id="verif-nav">
|
|
<div class="verif-nav-title">Dashboard</div>
|
|
<a href="#/" data-hash="#/"><span class="t">Overview</span></a>
|
|
@foreach($verifGroups as $verifTag => $verifOps)
|
|
<div class="verif-nav-title">{{ preg_replace('/(?<=[a-z])(?=[A-Z])/', ' ', $verifTag) }}</div>
|
|
@foreach($verifOps as $verifOp)
|
|
<a href="#/operations/{{ rawurlencode($verifOp['id']) }}" data-hash="#/operations/{{ rawurlencode($verifOp['id']) }}" title="{{ $verifOp['path'] }}">
|
|
<span class="m m-{{ $verifOp['method'] }}">{{ $verifOp['method'] }}</span>
|
|
<span class="t">{{ $verifOp['label'] }}</span>
|
|
</a>
|
|
@endforeach
|
|
@endforeach
|
|
</nav>
|
|
</aside>
|
|
<div class="verif-main">
|
|
<header class="verif-topbar">
|
|
<span>API Documentation</span>
|
|
</header>
|
|
<div class="verif-content">
|
|
<elements-api
|
|
id="docs"
|
|
@foreach($config->renderer()->all(except: ['theme']) as $key => $value)
|
|
@continue(! $value)
|
|
{{ $key }}="{{ $value === true ? 'true' : ($value === false ? 'false' : $value) }}"
|
|
@endforeach
|
|
/>
|
|
<script>
|
|
(async () => {
|
|
const docs = document.getElementById('docs');
|
|
docs.apiDescriptionDocument = @json($spec);
|
|
})();
|
|
|
|
// Tandai item sidebar yang aktif sesuai hash (router Elements memakai hash).
|
|
(() => {
|
|
const links = document.querySelectorAll('#verif-nav a');
|
|
const sync = () => {
|
|
const hash = location.hash || '#/';
|
|
links.forEach((a) => {
|
|
const on = a.dataset.hash === hash;
|
|
a.classList.toggle('active', on);
|
|
if (on) a.scrollIntoView({ block: 'nearest' });
|
|
});
|
|
};
|
|
addEventListener('hashchange', sync);
|
|
sync();
|
|
})();
|
|
</script>
|
|
|
|
@if($config->renderer()->get('theme', 'light') === 'system')
|
|
<script>
|
|
var mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
function updateTheme(e) {
|
|
if (e.matches) {
|
|
window.document.documentElement.setAttribute('data-theme', 'dark');
|
|
window.document.getElementsByName('color-scheme')[0].setAttribute('content', 'dark');
|
|
} else {
|
|
window.document.documentElement.setAttribute('data-theme', 'light');
|
|
window.document.getElementsByName('color-scheme')[0].setAttribute('content', 'light');
|
|
}
|
|
}
|
|
|
|
mediaQuery.addEventListener('change', updateTheme);
|
|
updateTheme(mediaQuery);
|
|
</script>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|