vector-framework 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +87 -635
  2. package/dist/auth/protected.d.ts.map +1 -1
  3. package/dist/auth/protected.js.map +1 -1
  4. package/dist/cache/manager.d.ts.map +1 -1
  5. package/dist/cache/manager.js +2 -7
  6. package/dist/cache/manager.js.map +1 -1
  7. package/dist/cli/index.js +17 -62
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/cli/option-resolution.d.ts +4 -0
  10. package/dist/cli/option-resolution.d.ts.map +1 -0
  11. package/dist/cli/option-resolution.js +28 -0
  12. package/dist/cli/option-resolution.js.map +1 -0
  13. package/dist/cli.js +2721 -617
  14. package/dist/constants/index.d.ts +3 -0
  15. package/dist/constants/index.d.ts.map +1 -1
  16. package/dist/constants/index.js +6 -0
  17. package/dist/constants/index.js.map +1 -1
  18. package/dist/core/config-loader.d.ts.map +1 -1
  19. package/dist/core/config-loader.js +2 -0
  20. package/dist/core/config-loader.js.map +1 -1
  21. package/dist/core/router.d.ts +41 -17
  22. package/dist/core/router.d.ts.map +1 -1
  23. package/dist/core/router.js +432 -153
  24. package/dist/core/router.js.map +1 -1
  25. package/dist/core/server.d.ts +14 -1
  26. package/dist/core/server.d.ts.map +1 -1
  27. package/dist/core/server.js +250 -30
  28. package/dist/core/server.js.map +1 -1
  29. package/dist/core/vector.d.ts +4 -3
  30. package/dist/core/vector.d.ts.map +1 -1
  31. package/dist/core/vector.js +21 -12
  32. package/dist/core/vector.js.map +1 -1
  33. package/dist/dev/route-generator.d.ts.map +1 -1
  34. package/dist/dev/route-generator.js.map +1 -1
  35. package/dist/dev/route-scanner.d.ts.map +1 -1
  36. package/dist/dev/route-scanner.js +1 -5
  37. package/dist/dev/route-scanner.js.map +1 -1
  38. package/dist/http.d.ts +14 -14
  39. package/dist/http.d.ts.map +1 -1
  40. package/dist/http.js +34 -41
  41. package/dist/http.js.map +1 -1
  42. package/dist/index.js +1314 -8
  43. package/dist/index.mjs +1314 -8
  44. package/dist/middleware/manager.d.ts.map +1 -1
  45. package/dist/middleware/manager.js +4 -0
  46. package/dist/middleware/manager.js.map +1 -1
  47. package/dist/openapi/docs-ui.d.ts +2 -0
  48. package/dist/openapi/docs-ui.d.ts.map +1 -0
  49. package/dist/openapi/docs-ui.js +1313 -0
  50. package/dist/openapi/docs-ui.js.map +1 -0
  51. package/dist/openapi/generator.d.ts +12 -0
  52. package/dist/openapi/generator.d.ts.map +1 -0
  53. package/dist/openapi/generator.js +273 -0
  54. package/dist/openapi/generator.js.map +1 -0
  55. package/dist/types/index.d.ts +70 -11
  56. package/dist/types/index.d.ts.map +1 -1
  57. package/dist/types/standard-schema.d.ts +118 -0
  58. package/dist/types/standard-schema.d.ts.map +1 -0
  59. package/dist/types/standard-schema.js +2 -0
  60. package/dist/types/standard-schema.js.map +1 -0
  61. package/dist/utils/cors.d.ts +13 -0
  62. package/dist/utils/cors.d.ts.map +1 -0
  63. package/dist/utils/cors.js +89 -0
  64. package/dist/utils/cors.js.map +1 -0
  65. package/dist/utils/path.d.ts +6 -0
  66. package/dist/utils/path.d.ts.map +1 -1
  67. package/dist/utils/path.js +5 -0
  68. package/dist/utils/path.js.map +1 -1
  69. package/dist/utils/schema-validation.d.ts +31 -0
  70. package/dist/utils/schema-validation.d.ts.map +1 -0
  71. package/dist/utils/schema-validation.js +77 -0
  72. package/dist/utils/schema-validation.js.map +1 -0
  73. package/dist/utils/validation.d.ts.map +1 -1
  74. package/dist/utils/validation.js +1 -0
  75. package/dist/utils/validation.js.map +1 -1
  76. package/package.json +13 -12
  77. package/src/auth/protected.ts +3 -13
  78. package/src/cache/manager.ts +4 -18
  79. package/src/cli/index.ts +19 -75
  80. package/src/cli/option-resolution.ts +40 -0
  81. package/src/constants/index.ts +7 -0
  82. package/src/core/config-loader.ts +3 -3
  83. package/src/core/router.ts +502 -156
  84. package/src/core/server.ts +327 -32
  85. package/src/core/vector.ts +49 -29
  86. package/src/dev/route-generator.ts +1 -3
  87. package/src/dev/route-scanner.ts +2 -9
  88. package/src/http.ts +85 -125
  89. package/src/middleware/manager.ts +4 -0
  90. package/src/openapi/assets/tailwindcdn.js +83 -0
  91. package/src/openapi/docs-ui.ts +1317 -0
  92. package/src/openapi/generator.ts +359 -0
  93. package/src/types/index.ts +104 -17
  94. package/src/types/standard-schema.ts +147 -0
  95. package/src/utils/cors.ts +101 -0
  96. package/src/utils/path.ts +6 -0
  97. package/src/utils/schema-validation.ts +123 -0
  98. package/src/utils/validation.ts +1 -0
@@ -0,0 +1,1317 @@
1
+ export function renderOpenAPIDocsHtml(
2
+ spec: Record<string, unknown>,
3
+ openapiPath: string,
4
+ tailwindScriptPath: string
5
+ ): string {
6
+ const specJson = JSON.stringify(spec).replace(/<\/script/gi, '<\\/script');
7
+ const openapiPathJson = JSON.stringify(openapiPath);
8
+ const tailwindScriptPathJson = JSON.stringify(tailwindScriptPath);
9
+
10
+ return `<!DOCTYPE html>
11
+ <html lang="en">
12
+ <head>
13
+ <meta charset="UTF-8">
14
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
15
+ <title>Vector API Documentation</title>
16
+ <script>
17
+ if (localStorage.getItem('theme') === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
18
+ document.documentElement.classList.add('dark');
19
+ } else {
20
+ document.documentElement.classList.remove('dark');
21
+ }
22
+ </script>
23
+ <script src=${tailwindScriptPathJson}></script>
24
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
25
+ <script>
26
+ tailwind.config = {
27
+ darkMode: 'class',
28
+ theme: {
29
+ extend: {
30
+ colors: {
31
+ brand: '#6366F1',
32
+ dark: { bg: '#0A0A0A', surface: '#111111', border: '#1F1F1F', text: '#EDEDED' },
33
+ light: { bg: '#FFFFFF', surface: '#F9F9F9', border: '#E5E5E5', text: '#111111' }
34
+ },
35
+ fontFamily: {
36
+ sans: ['Inter', 'sans-serif'],
37
+ mono: ['JetBrains Mono', 'monospace'],
38
+ }
39
+ }
40
+ }
41
+ };
42
+ </script>
43
+ <style>
44
+ :root {
45
+ --motion-fast: 180ms;
46
+ --motion-base: 280ms;
47
+ --motion-slow: 420ms;
48
+ --motion-ease: cubic-bezier(0.22, 1, 0.36, 1);
49
+ }
50
+ ::-webkit-scrollbar { width: 8px; height: 8px; }
51
+ ::-webkit-scrollbar-track { background: transparent; }
52
+ ::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
53
+ body { transition: background-color 150ms ease, color 150ms ease; }
54
+ #sidebar-nav a,
55
+ #send-btn,
56
+ #copy-curl,
57
+ #add-header-btn,
58
+ #expand-body-btn,
59
+ #expand-response-btn,
60
+ #expand-close,
61
+ #expand-apply {
62
+ transition:
63
+ transform var(--motion-fast) var(--motion-ease),
64
+ opacity var(--motion-fast) var(--motion-ease),
65
+ border-color var(--motion-fast) var(--motion-ease),
66
+ background-color var(--motion-fast) var(--motion-ease),
67
+ color var(--motion-fast) var(--motion-ease);
68
+ will-change: transform, opacity;
69
+ }
70
+ #sidebar-nav a:hover,
71
+ #send-btn:hover,
72
+ #add-header-btn:hover,
73
+ #expand-body-btn:hover,
74
+ #expand-response-btn:hover {
75
+ transform: translateY(-1px);
76
+ }
77
+ #endpoint-card {
78
+ transition:
79
+ box-shadow var(--motion-base) var(--motion-ease),
80
+ transform var(--motion-base) var(--motion-ease),
81
+ opacity var(--motion-base) var(--motion-ease);
82
+ }
83
+ .enter-fade-up {
84
+ animation: enterFadeUp var(--motion-base) var(--motion-ease) both;
85
+ }
86
+ .enter-stagger {
87
+ animation: enterStagger var(--motion-base) var(--motion-ease) both;
88
+ animation-delay: var(--stagger-delay, 0ms);
89
+ }
90
+ @keyframes enterFadeUp {
91
+ from { opacity: 0; transform: translateY(8px); }
92
+ to { opacity: 1; transform: translateY(0); }
93
+ }
94
+ @keyframes enterStagger {
95
+ from { opacity: 0; transform: translateX(-6px); }
96
+ to { opacity: 1; transform: translateX(0); }
97
+ }
98
+ @media (prefers-reduced-motion: reduce) {
99
+ *, *::before, *::after {
100
+ animation: none !important;
101
+ transition: none !important;
102
+ }
103
+ }
104
+ .json-key { color: #0f766e; }
105
+ .json-string { color: #0369a1; }
106
+ .json-number { color: #7c3aed; }
107
+ .json-boolean { color: #b45309; }
108
+ .json-null { color: #be123c; }
109
+ .dark .json-key { color: #5eead4; }
110
+ .dark .json-string { color: #7dd3fc; }
111
+ .dark .json-number { color: #c4b5fd; }
112
+ .dark .json-boolean { color: #fcd34d; }
113
+ .dark .json-null { color: #fda4af; }
114
+ </style>
115
+ </head>
116
+ <body class="bg-light-bg text-light-text dark:bg-dark-bg dark:text-dark-text font-sans antialiased flex h-screen overflow-hidden">
117
+ <div id="mobile-backdrop" class="fixed inset-0 z-30 bg-black/40 opacity-0 pointer-events-none transition-opacity duration-300 md:hidden"></div>
118
+ <aside id="docs-sidebar" class="fixed inset-y-0 left-0 z-40 w-72 md:w-64 border-r border-light-border dark:border-dark-border bg-light-surface dark:bg-dark-surface flex flex-col flex-shrink-0 transition-transform duration-300 ease-out -translate-x-full md:translate-x-0 md:static md:z-auto transition-colors duration-150">
119
+ <div class="h-14 flex items-center px-5 border-b border-light-border dark:border-dark-border">
120
+ <svg class="w-5 h-5 text-brand" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
121
+ <polygon points="3 21 12 2 21 21 12 15 3 21"></polygon>
122
+ </svg>
123
+ <span class="ml-2.5 font-bold tracking-tight text-lg">Vector</span>
124
+ <button id="sidebar-close" class="ml-auto p-1.5 rounded-full border border-light-border dark:border-dark-border bg-light-bg/90 dark:bg-dark-bg/90 opacity-90 hover:opacity-100 transition md:hidden" aria-label="Close Menu" title="Close Menu">
125
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
126
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
127
+ </svg>
128
+ </button>
129
+ </div>
130
+ <div class="p-4">
131
+ <div class="relative">
132
+ <svg class="w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 opacity-60" fill="none" stroke="currentColor" viewBox="0 0 24 24">
133
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
134
+ </svg>
135
+ <input
136
+ id="sidebar-search"
137
+ type="text"
138
+ placeholder="Search routes..."
139
+ class="w-full pl-9 pr-3 py-2 text-sm rounded-md border border-light-border dark:border-dark-border bg-light-bg dark:bg-dark-bg focus:outline-none focus:border-brand dark:focus:border-brand transition-colors"
140
+ />
141
+ </div>
142
+ </div>
143
+ <nav class="flex-1 overflow-y-auto px-3 py-2 space-y-6 text-sm" id="sidebar-nav"></nav>
144
+ </aside>
145
+
146
+ <main class="flex-1 flex flex-col min-w-0 relative">
147
+ <header class="h-14 flex items-center justify-between px-6 border-b border-light-border dark:border-dark-border lg:border-none lg:bg-transparent absolute top-0 w-full z-10 bg-light-bg/80 dark:bg-dark-bg/80 backdrop-blur-sm transition-colors duration-150">
148
+ <div class="md:hidden flex items-center gap-2">
149
+ <button id="sidebar-open" class="p-1.5 rounded-full border border-light-border dark:border-dark-border bg-light-bg/90 dark:bg-dark-bg/90 opacity-90 hover:opacity-100 transition" aria-label="Open Menu" title="Open Menu">
150
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
151
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
152
+ </svg>
153
+ </button>
154
+ <svg class="w-5 h-5 text-brand" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="3 21 12 2 21 21 12 15 3 21"></polygon></svg>
155
+ <span class="font-bold tracking-tight">Vector</span>
156
+ </div>
157
+ <div class="flex-1"></div>
158
+ <button id="theme-toggle" class="p-2 rounded-md hover:bg-black/5 dark:hover:bg-white/5 transition-colors" aria-label="Toggle Dark Mode">
159
+ <svg class="w-5 h-5 hidden dark:block text-dark-text" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"></path></svg>
160
+ <svg class="w-5 h-5 block dark:hidden text-light-text" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path></svg>
161
+ </button>
162
+ </header>
163
+
164
+ <div class="flex-1 overflow-y-auto pt-14 pb-24">
165
+ <div class="max-w-[860px] mx-auto px-6 py-12 lg:py-16">
166
+ <div class="mb-12">
167
+ <h1 class="text-4xl font-bold tracking-tight mb-4" id="tag-title">API</h1>
168
+ <p class="text-lg opacity-80 max-w-2xl leading-relaxed" id="tag-description">Interactive API documentation.</p>
169
+ </div>
170
+ <hr class="border-t border-light-border dark:border-dark-border mb-12">
171
+ <div class="mb-20" id="endpoint-card">
172
+ <div class="flex items-center gap-3 mb-4">
173
+ <span id="endpoint-method" class="px-2.5 py-0.5 rounded-full text-xs font-mono font-medium"></span>
174
+ <h2 class="text-xl font-semibold tracking-tight" id="endpoint-title">Operation</h2>
175
+ </div>
176
+ <p class="text-sm opacity-80 mb-8 font-mono" id="endpoint-path">/</p>
177
+ <div class="grid grid-cols-1 lg:grid-cols-12 gap-10">
178
+ <div class="lg:col-span-5 space-y-8" id="params-column"></div>
179
+ <div class="lg:col-span-7">
180
+ <div class="rounded-lg border border-light-border dark:border-[#1F1F1F] bg-light-bg dark:bg-[#111111] overflow-hidden group">
181
+ <div class="flex items-center justify-between px-4 py-2 border-b border-light-border dark:border-[#1F1F1F] bg-light-surface dark:bg-[#0A0A0A]">
182
+ <span class="text-xs font-mono text-light-text/70 dark:text-[#EDEDED]/70">cURL</span>
183
+ <button class="text-xs text-light-text/50 hover:text-light-text dark:text-[#EDEDED]/50 dark:hover:text-[#EDEDED] transition-colors" id="copy-curl">Copy</button>
184
+ </div>
185
+ <pre class="p-4 text-sm font-mono text-light-text dark:text-[#EDEDED] overflow-x-auto leading-relaxed"><code id="curl-code"></code></pre>
186
+ </div>
187
+ <div class="mt-4 p-4 rounded-lg border border-light-border dark:border-dark-border bg-light-surface dark:bg-dark-surface">
188
+ <div class="flex items-center justify-between mb-3">
189
+ <h4 class="text-sm font-medium">Try it out</h4>
190
+ <button id="send-btn" class="px-4 py-1.5 bg-teal-600 text-white text-sm font-semibold rounded hover:bg-teal-500 transition-colors">Submit</button>
191
+ </div>
192
+ <div class="space-y-4">
193
+ <div>
194
+ <div id="request-param-inputs" class="space-y-3"></div>
195
+ </div>
196
+
197
+ <div>
198
+ <div class="flex items-center justify-between mb-2">
199
+ <p class="text-xs font-semibold uppercase tracking-wider opacity-60">Headers</p>
200
+ <button id="add-header-btn" class="p-1.5 rounded-full border border-light-border dark:border-dark-border bg-light-bg/90 dark:bg-dark-bg/90 opacity-90 hover:opacity-100 hover:border-brand/60 transition-colors" aria-label="Add Header" title="Add Header">
201
+ <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
202
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v14m-7-7h14"></path>
203
+ </svg>
204
+ </button>
205
+ </div>
206
+ <div id="header-inputs" class="space-y-2"></div>
207
+ </div>
208
+
209
+ <div id="request-body-section">
210
+ <div class="flex items-center justify-between mb-2">
211
+ <p class="text-xs font-semibold uppercase tracking-wider opacity-60">Request Body</p>
212
+ </div>
213
+ <div class="relative h-40 rounded border border-light-border dark:border-dark-border bg-light-bg dark:bg-dark-bg overflow-hidden">
214
+ <pre id="body-highlight" class="absolute inset-0 m-0 p-3 pr-11 text-xs font-mono leading-5 overflow-auto whitespace-pre-wrap break-words pointer-events-none"></pre>
215
+ <textarea id="body-input" class="absolute inset-0 w-full h-full p-3 pr-11 text-xs font-mono leading-5 bg-transparent text-transparent caret-black dark:caret-white resize-none focus:outline-none overflow-auto placeholder:text-light-text/50 dark:placeholder:text-dark-text/40" placeholder='{"key":"value"}' spellcheck="false" autocapitalize="off" autocorrect="off"></textarea>
216
+ <button id="expand-body-btn" class="absolute bottom-2 right-2 p-1.5 rounded-full border border-light-border dark:border-dark-border bg-light-surface/95 dark:bg-dark-surface/95 opacity-90 hover:opacity-100 hover:border-brand/60 transition-colors" aria-label="Expand Request Body" title="Expand Request Body">
217
+ <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
218
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 9V4h5M20 15v5h-5M15 4h5v5M9 20H4v-5"></path>
219
+ </svg>
220
+ </button>
221
+ </div>
222
+ </div>
223
+
224
+ <div>
225
+ <div class="flex items-center justify-between mb-2">
226
+ <p class="text-xs font-semibold uppercase tracking-wider opacity-60">Response</p>
227
+ </div>
228
+ <div class="relative">
229
+ <pre id="result" class="p-3 pr-11 text-xs font-mono rounded border border-light-border dark:border-dark-border overflow-x-auto min-h-[140px]"></pre>
230
+ <button id="expand-response-btn" class="absolute bottom-2 right-2 p-1.5 rounded-full border border-light-border dark:border-dark-border bg-light-surface/95 dark:bg-dark-surface/95 opacity-90 hover:opacity-100 hover:border-brand/60 transition-colors" aria-label="Expand Response" title="Expand Response">
231
+ <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
232
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 9V4h5M20 15v5h-5M15 4h5v5M9 20H4v-5"></path>
233
+ </svg>
234
+ </button>
235
+ </div>
236
+ </div>
237
+ </div>
238
+ </div>
239
+ </div>
240
+ </div>
241
+ </div>
242
+ </div>
243
+ </div>
244
+ </main>
245
+
246
+ <div id="expand-modal" class="fixed inset-0 z-50 hidden items-center justify-center bg-black/60 p-4">
247
+ <div class="w-full max-w-5xl rounded-lg border border-light-border dark:border-dark-border bg-light-surface dark:bg-dark-surface p-4">
248
+ <div class="flex items-center justify-between mb-3">
249
+ <h3 id="expand-modal-title" class="text-sm font-semibold">Expanded View</h3>
250
+ <div class="flex items-center gap-2">
251
+ <button id="expand-apply" class="hidden text-sm px-3 py-1.5 rounded bg-teal-600 text-white font-semibold hover:bg-teal-500 transition-colors">Apply</button>
252
+ <button id="expand-close" class="p-1.5 rounded-full border border-light-border dark:border-dark-border bg-light-bg/90 dark:bg-dark-bg/90 opacity-90 hover:opacity-100 hover:border-brand/60 transition-colors" aria-label="Close Modal" title="Close Modal">
253
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
254
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
255
+ </svg>
256
+ </button>
257
+ </div>
258
+ </div>
259
+ <div id="expand-editor-shell" class="hidden relative w-full h-[70vh] rounded border border-light-border dark:border-dark-border bg-light-bg dark:bg-dark-bg overflow-hidden">
260
+ <pre id="expand-editor-highlight" class="absolute inset-0 m-0 p-3 text-sm font-mono leading-6 overflow-auto whitespace-pre-wrap break-words pointer-events-none"></pre>
261
+ <textarea id="expand-editor" class="absolute inset-0 w-full h-full p-3 text-sm font-mono leading-6 bg-transparent text-transparent caret-black dark:caret-white resize-none focus:outline-none overflow-auto" spellcheck="false" autocapitalize="off" autocorrect="off"></textarea>
262
+ </div>
263
+ <pre id="expand-viewer" class="hidden w-full h-[70vh] text-sm p-3 rounded border border-light-border dark:border-dark-border bg-light-bg dark:bg-dark-bg overflow-auto font-mono"></pre>
264
+ </div>
265
+ </div>
266
+
267
+ <script>
268
+ const spec = ${specJson};
269
+ const openapiPath = ${openapiPathJson};
270
+ const methodBadge = {
271
+ GET: "bg-green-100 text-green-700 dark:bg-green-500/10 dark:text-green-400",
272
+ POST: "bg-blue-100 text-blue-700 dark:bg-blue-500/10 dark:text-blue-400",
273
+ PUT: "bg-amber-100 text-amber-700 dark:bg-amber-500/10 dark:text-amber-400",
274
+ PATCH: "bg-amber-100 text-amber-700 dark:bg-amber-500/10 dark:text-amber-400",
275
+ DELETE: "bg-red-100 text-red-700 dark:bg-red-500/10 dark:text-red-400",
276
+ };
277
+
278
+ function getOperations() {
279
+ const httpMethods = new Set([
280
+ "get",
281
+ "post",
282
+ "put",
283
+ "patch",
284
+ "delete",
285
+ "head",
286
+ "options",
287
+ ]);
288
+
289
+ const humanizePath = (path) =>
290
+ path
291
+ .replace(/^\\/+/, "")
292
+ .replace(/[{}]/g, "")
293
+ .replace(/[\\/_]+/g, " ")
294
+ .trim() || "root";
295
+
296
+ const toTitleCase = (value) =>
297
+ value.replace(/\\w\\S*/g, (word) => word.charAt(0).toUpperCase() + word.slice(1));
298
+
299
+ const getDisplayName = (op, method, path) => {
300
+ if (typeof op.summary === "string" && op.summary.trim()) {
301
+ return op.summary.trim();
302
+ }
303
+
304
+ if (typeof op.operationId === "string" && op.operationId.trim()) {
305
+ const withoutPrefix = op.operationId.replace(
306
+ new RegExp("^" + method + "_+", "i"),
307
+ "",
308
+ );
309
+ const readable = withoutPrefix.replace(/_+/g, " ").trim();
310
+ if (readable) return toTitleCase(readable);
311
+ }
312
+
313
+ return toTitleCase(humanizePath(path));
314
+ };
315
+
316
+ const ops = [];
317
+ const paths = spec.paths || {};
318
+ for (const path of Object.keys(paths)) {
319
+ const methods = paths[path] || {};
320
+ for (const method of Object.keys(methods)) {
321
+ if (!httpMethods.has(method)) continue;
322
+ const op = methods[method];
323
+ ops.push({
324
+ path,
325
+ method: method.toUpperCase(),
326
+ operation: op,
327
+ tag: (op.tags && op.tags[0]) || "default",
328
+ name: getDisplayName(op, method, path),
329
+ });
330
+ }
331
+ }
332
+ return ops;
333
+ }
334
+
335
+ const operations = getOperations();
336
+ let selected = operations[0] || null;
337
+ const operationParamValues = new Map();
338
+ const operationBodyDrafts = new Map();
339
+ const requestHeaders = [{ key: "Authorization", value: "" }];
340
+ let expandModalMode = null;
341
+ let isMobileSidebarOpen = false;
342
+ let sidebarSearchQuery = "";
343
+
344
+ function setMobileSidebarOpen(open) {
345
+ const sidebar = document.getElementById("docs-sidebar");
346
+ const backdrop = document.getElementById("mobile-backdrop");
347
+ const openBtn = document.getElementById("sidebar-open");
348
+ if (!sidebar || !backdrop || !openBtn) return;
349
+
350
+ isMobileSidebarOpen = open;
351
+ sidebar.classList.toggle("-translate-x-full", !open);
352
+ backdrop.classList.toggle("opacity-0", !open);
353
+ backdrop.classList.toggle("pointer-events-none", !open);
354
+ openBtn.setAttribute("aria-expanded", open ? "true" : "false");
355
+ document.body.classList.toggle("overflow-hidden", open);
356
+ }
357
+
358
+ function getOperationKey(op) {
359
+ return op.method + " " + op.path;
360
+ }
361
+
362
+ function getOperationParameterGroups(op) {
363
+ const params =
364
+ op &&
365
+ op.operation &&
366
+ Array.isArray(op.operation.parameters)
367
+ ? op.operation.parameters
368
+ : [];
369
+
370
+ return {
371
+ all: params,
372
+ path: params.filter((p) => p.in === "path"),
373
+ query: params.filter((p) => p.in === "query"),
374
+ headers: params.filter((p) => p.in === "header"),
375
+ };
376
+ }
377
+
378
+ function getParameterValues(op) {
379
+ const key = getOperationKey(op);
380
+ if (!operationParamValues.has(key)) {
381
+ operationParamValues.set(key, {});
382
+ }
383
+ return operationParamValues.get(key);
384
+ }
385
+
386
+ function getBodyDraft(op) {
387
+ const key = getOperationKey(op);
388
+ return operationBodyDrafts.get(key);
389
+ }
390
+
391
+ function setBodyDraft(op, bodyValue) {
392
+ const key = getOperationKey(op);
393
+ operationBodyDrafts.set(key, bodyValue);
394
+ }
395
+
396
+ function resolvePath(pathTemplate, pathParams, values) {
397
+ let resolved = pathTemplate;
398
+ for (const param of pathParams) {
399
+ const rawValue = values[param.name];
400
+ if (rawValue === undefined || rawValue === null || rawValue === "") {
401
+ continue;
402
+ }
403
+ const placeholder = "{" + param.name + "}";
404
+ resolved = resolved
405
+ .split(placeholder)
406
+ .join(encodeURIComponent(String(rawValue)));
407
+ }
408
+ return resolved;
409
+ }
410
+
411
+ function buildRequestPath(op, pathParams, queryParams, values) {
412
+ const resolvedPath = resolvePath(op.path, pathParams, values);
413
+ const query = new URLSearchParams();
414
+
415
+ for (const param of queryParams) {
416
+ const rawValue = values[param.name];
417
+ if (rawValue === undefined || rawValue === null || rawValue === "") {
418
+ continue;
419
+ }
420
+ query.append(param.name, String(rawValue));
421
+ }
422
+
423
+ const queryString = query.toString();
424
+ return queryString ? resolvedPath + "?" + queryString : resolvedPath;
425
+ }
426
+
427
+ function schemaDefaultValue(schema) {
428
+ if (!schema || typeof schema !== "object") return null;
429
+ if (schema.default !== undefined) return schema.default;
430
+ if (schema.example !== undefined) return schema.example;
431
+ if (Array.isArray(schema.enum) && schema.enum.length > 0) return schema.enum[0];
432
+ if (Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {
433
+ return schemaDefaultValue(schema.oneOf[0]);
434
+ }
435
+ if (Array.isArray(schema.anyOf) && schema.anyOf.length > 0) {
436
+ return schemaDefaultValue(schema.anyOf[0]);
437
+ }
438
+ if (Array.isArray(schema.allOf) && schema.allOf.length > 0) {
439
+ return schemaDefaultValue(schema.allOf[0]);
440
+ }
441
+
442
+ switch (schema.type) {
443
+ case "string":
444
+ return "";
445
+ case "number":
446
+ case "integer":
447
+ return 0;
448
+ case "boolean":
449
+ return false;
450
+ case "array":
451
+ return [];
452
+ case "object": {
453
+ const required = Array.isArray(schema.required) ? schema.required : [];
454
+ const properties = schema.properties && typeof schema.properties === "object"
455
+ ? schema.properties
456
+ : {};
457
+ const obj = {};
458
+ for (const fieldName of required) {
459
+ obj[fieldName] = schemaDefaultValue(properties[fieldName]);
460
+ }
461
+ return obj;
462
+ }
463
+ default:
464
+ return null;
465
+ }
466
+ }
467
+
468
+ function buildRequiredBodyPrefill(schema) {
469
+ if (!schema || typeof schema !== "object") return "";
470
+ const prefillValue = schemaDefaultValue(schema);
471
+ if (
472
+ prefillValue &&
473
+ typeof prefillValue === "object" &&
474
+ !Array.isArray(prefillValue) &&
475
+ Object.keys(prefillValue).length === 0
476
+ ) {
477
+ return "";
478
+ }
479
+ try {
480
+ return JSON.stringify(prefillValue, null, 2);
481
+ } catch {
482
+ return "";
483
+ }
484
+ }
485
+
486
+ function hasMeaningfulRequestBodySchema(schema) {
487
+ if (!schema || typeof schema !== "object") return false;
488
+ if (Array.isArray(schema.oneOf) && schema.oneOf.length > 0) return true;
489
+ if (Array.isArray(schema.anyOf) && schema.anyOf.length > 0) return true;
490
+ if (Array.isArray(schema.allOf) && schema.allOf.length > 0) return true;
491
+ if (schema.type && schema.type !== "object") return true;
492
+ if (schema.additionalProperties !== undefined) return true;
493
+ if (Array.isArray(schema.required) && schema.required.length > 0) return true;
494
+ if (schema.properties && typeof schema.properties === "object") {
495
+ return Object.keys(schema.properties).length > 0;
496
+ }
497
+ return false;
498
+ }
499
+
500
+ function renderSidebar() {
501
+ const nav = document.getElementById("sidebar-nav");
502
+ const groups = new Map();
503
+ const query = sidebarSearchQuery.trim().toLowerCase();
504
+ const visibleOps = query
505
+ ? operations.filter((op) => {
506
+ const haystack = [
507
+ op.name,
508
+ op.path,
509
+ op.method,
510
+ op.tag,
511
+ ]
512
+ .join(" ")
513
+ .toLowerCase();
514
+ return haystack.includes(query);
515
+ })
516
+ : operations;
517
+
518
+ for (const op of visibleOps) {
519
+ if (!groups.has(op.tag)) groups.set(op.tag, []);
520
+ groups.get(op.tag).push(op);
521
+ }
522
+ nav.innerHTML = "";
523
+ if (visibleOps.length === 0) {
524
+ nav.innerHTML =
525
+ '<p class="px-2 text-xs opacity-60">No routes match your search.</p>';
526
+ return;
527
+ }
528
+ for (const [tag, ops] of groups.entries()) {
529
+ const block = document.createElement("div");
530
+ block.innerHTML = '<h3 class="px-2 mb-2 font-semibold text-xs uppercase tracking-wider opacity-50"></h3><ul class="space-y-0.5"></ul>';
531
+ block.querySelector("h3").textContent = tag;
532
+ const list = block.querySelector("ul");
533
+ for (const op of ops) {
534
+ const li = document.createElement("li");
535
+ li.className = "enter-stagger";
536
+ li.style.setProperty("--stagger-delay", String(Math.min(list.children.length * 22, 180)) + "ms");
537
+ const a = document.createElement("a");
538
+ a.href = "#";
539
+ a.className = op === selected
540
+ ? "block px-2 py-1.5 rounded-md bg-black/5 dark:bg-white/5 text-brand font-medium transition-colors"
541
+ : "block px-2 py-1.5 rounded-md hover:bg-black/5 dark:hover:bg-white/5 transition-colors";
542
+
543
+ const row = document.createElement("span");
544
+ row.className = "flex items-center gap-2";
545
+
546
+ const method = document.createElement("span");
547
+ method.className = "px-1.5 py-0.5 rounded text-[10px] font-mono font-semibold " + (methodBadge[op.method] || "bg-zinc-100 text-zinc-700 dark:bg-zinc-500/10 dark:text-zinc-400");
548
+ method.textContent = op.method;
549
+
550
+ const name = document.createElement("span");
551
+ name.textContent = op.name;
552
+
553
+ row.appendChild(method);
554
+ row.appendChild(name);
555
+ a.appendChild(row);
556
+
557
+ a.onclick = (e) => {
558
+ e.preventDefault();
559
+ selected = op;
560
+ renderSidebar();
561
+ renderEndpoint();
562
+ if (window.innerWidth < 768) {
563
+ setMobileSidebarOpen(false);
564
+ }
565
+ };
566
+ li.appendChild(a);
567
+ list.appendChild(li);
568
+ }
569
+ nav.appendChild(block);
570
+ }
571
+ }
572
+
573
+ function renderParamSection(title, params) {
574
+ if (!params.length) return "";
575
+ let rows = "";
576
+ for (const p of params) {
577
+ const type = escapeHtml((p.schema && p.schema.type) || "unknown");
578
+ const name = escapeHtml(p.name || "");
579
+ rows += '<div class="py-2 flex justify-between border-b border-light-border/50 dark:border-dark-border/50"><div><code class="text-sm font-mono">' + name + '</code><span class="text-xs text-brand ml-2">' + (p.required ? "required" : "optional") + '</span></div><span class="text-xs font-mono opacity-60">' + type + '</span></div>';
580
+ }
581
+ return '<div><h3 class="text-sm font-semibold mb-3 flex items-center border-b border-light-border dark:border-dark-border pb-2">' + escapeHtml(title) + "</h3>" + rows + "</div>";
582
+ }
583
+
584
+ function getSchemaTypeLabel(schema) {
585
+ if (!schema || typeof schema !== "object") return "unknown";
586
+ if (Array.isArray(schema.type)) return schema.type.join(" | ");
587
+ if (schema.type) return String(schema.type);
588
+ if (schema.properties) return "object";
589
+ if (schema.items) return "array";
590
+ if (Array.isArray(schema.oneOf)) return "oneOf";
591
+ if (Array.isArray(schema.anyOf)) return "anyOf";
592
+ if (Array.isArray(schema.allOf)) return "allOf";
593
+ return "unknown";
594
+ }
595
+
596
+ function buildSchemaChildren(schema) {
597
+ if (!schema || typeof schema !== "object") return [];
598
+
599
+ const children = [];
600
+
601
+ if (schema.properties && typeof schema.properties === "object") {
602
+ const requiredSet = new Set(
603
+ Array.isArray(schema.required) ? schema.required : [],
604
+ );
605
+ for (const [name, childSchema] of Object.entries(schema.properties)) {
606
+ children.push({
607
+ name,
608
+ schema: childSchema || {},
609
+ required: requiredSet.has(name),
610
+ });
611
+ }
612
+ }
613
+
614
+ if (schema.items) {
615
+ children.push({
616
+ name: "items[]",
617
+ schema: schema.items,
618
+ required: true,
619
+ });
620
+ }
621
+
622
+ return children;
623
+ }
624
+
625
+ function renderSchemaFieldNode(field, depth) {
626
+ const schema = field.schema || {};
627
+ const name = escapeHtml(field.name || "field");
628
+ const requiredLabel = field.required ? "required" : "optional";
629
+ const type = escapeHtml(getSchemaTypeLabel(schema));
630
+ const children = buildSchemaChildren(schema);
631
+ const padding = depth * 14;
632
+
633
+ if (!children.length) {
634
+ return (
635
+ '<div class="py-2 border-b border-light-border/50 dark:border-dark-border/50" style="padding-left:' +
636
+ padding +
637
+ 'px"><div class="flex justify-between"><div><code class="text-sm font-mono">' +
638
+ name +
639
+ '</code><span class="text-xs text-brand ml-2">' +
640
+ requiredLabel +
641
+ '</span></div><span class="text-xs font-mono opacity-60">' +
642
+ type +
643
+ "</span></div></div>"
644
+ );
645
+ }
646
+
647
+ let nested = "";
648
+ for (const child of children) {
649
+ nested += renderSchemaFieldNode(child, depth + 1);
650
+ }
651
+
652
+ return (
653
+ '<details class="border-b border-light-border/50 dark:border-dark-border/50" open>' +
654
+ '<summary class="list-none cursor-pointer py-2 flex justify-between items-center" style="padding-left:' +
655
+ padding +
656
+ 'px"><div class="flex items-center gap-2"><span class="text-xs opacity-70">▾</span><code class="text-sm font-mono">' +
657
+ name +
658
+ '</code><span class="text-xs text-brand">' +
659
+ requiredLabel +
660
+ '</span></div><span class="text-xs font-mono opacity-60">' +
661
+ type +
662
+ "</span></summary>" +
663
+ '<div class="pb-1">' +
664
+ nested +
665
+ "</div></details>"
666
+ );
667
+ }
668
+
669
+ function renderRequestBodySchemaSection(schema) {
670
+ if (!schema || typeof schema !== "object") return "";
671
+ const rootChildren = buildSchemaChildren(schema);
672
+ if (!rootChildren.length) return "";
673
+
674
+ let rows = "";
675
+ for (const child of rootChildren) {
676
+ rows += renderSchemaFieldNode(child, 0);
677
+ }
678
+
679
+ return (
680
+ '<div><h3 class="text-sm font-semibold mb-3 flex items-center border-b border-light-border dark:border-dark-border pb-2">Request Body</h3>' +
681
+ rows +
682
+ "</div>"
683
+ );
684
+ }
685
+
686
+ function renderTryItParameterInputs(pathParams, queryParams) {
687
+ const container = document.getElementById("request-param-inputs");
688
+ if (!container || !selected) return;
689
+
690
+ const values = getParameterValues(selected);
691
+ container.innerHTML = "";
692
+
693
+ const sections = [
694
+ { title: "Path Values", params: pathParams },
695
+ { title: "Query Values", params: queryParams },
696
+ ];
697
+
698
+ for (const section of sections) {
699
+ if (!section.params.length) continue;
700
+
701
+ const group = document.createElement("div");
702
+ group.className = "space-y-2";
703
+
704
+ const title = document.createElement("p");
705
+ title.className = "text-xs font-semibold uppercase tracking-wider opacity-60";
706
+ title.textContent = section.title;
707
+ group.appendChild(title);
708
+
709
+ for (const param of section.params) {
710
+ const field = document.createElement("div");
711
+ field.className = "space-y-1";
712
+
713
+ const label = document.createElement("label");
714
+ label.className = "text-xs opacity-80 flex items-center gap-2";
715
+
716
+ const labelName = document.createElement("span");
717
+ labelName.className = "font-mono";
718
+ labelName.textContent = param.name;
719
+
720
+ const required = document.createElement("span");
721
+ required.className = "text-[10px] text-brand";
722
+ required.textContent = param.required ? "required" : "optional";
723
+
724
+ label.appendChild(labelName);
725
+ label.appendChild(required);
726
+
727
+ const input = document.createElement("input");
728
+ input.type = "text";
729
+ input.value = values[param.name] || "";
730
+ input.placeholder =
731
+ section.title === "Path Values" ? param.name : "optional";
732
+ input.className =
733
+ "w-full text-sm px-3 py-2 rounded border border-light-border dark:border-dark-border bg-light-bg dark:bg-dark-bg focus:outline-none focus:border-brand dark:focus:border-brand transition-colors font-mono";
734
+
735
+ input.addEventListener("input", () => {
736
+ values[param.name] = input.value;
737
+ updateRequestPreview();
738
+ });
739
+
740
+ field.appendChild(label);
741
+ field.appendChild(input);
742
+ group.appendChild(field);
743
+ }
744
+
745
+ container.appendChild(group);
746
+ }
747
+ }
748
+
749
+ function renderHeaderInputs() {
750
+ const container = document.getElementById("header-inputs");
751
+ if (!container) return;
752
+
753
+ container.innerHTML = "";
754
+ requestHeaders.forEach((entry, index) => {
755
+ const row = document.createElement("div");
756
+ row.className = "grid grid-cols-[1fr_1fr_auto] gap-2";
757
+
758
+ const keyInput = document.createElement("input");
759
+ keyInput.type = "text";
760
+ keyInput.value = entry.key || "";
761
+ keyInput.placeholder = "Header";
762
+ keyInput.className =
763
+ "w-full text-xs px-2.5 py-2 rounded border border-light-border dark:border-dark-border bg-light-bg dark:bg-dark-bg focus:outline-none focus:border-brand dark:focus:border-brand transition-colors font-mono";
764
+ keyInput.addEventListener("input", () => {
765
+ entry.key = keyInput.value;
766
+ updateRequestPreview();
767
+ });
768
+
769
+ const valueInput = document.createElement("input");
770
+ valueInput.type = "text";
771
+ valueInput.value = entry.value || "";
772
+ valueInput.placeholder =
773
+ String(entry.key || "").toLowerCase() === "authorization"
774
+ ? "Bearer token"
775
+ : "Value";
776
+ valueInput.className =
777
+ "w-full text-xs px-2.5 py-2 rounded border border-light-border dark:border-dark-border bg-light-bg dark:bg-dark-bg focus:outline-none focus:border-brand dark:focus:border-brand transition-colors font-mono";
778
+ valueInput.addEventListener("input", () => {
779
+ entry.value = valueInput.value;
780
+ updateRequestPreview();
781
+ });
782
+
783
+ const removeButton = document.createElement("button");
784
+ removeButton.type = "button";
785
+ removeButton.className =
786
+ "p-1.5 rounded-full border border-light-border dark:border-dark-border bg-light-bg/90 dark:bg-dark-bg/90 opacity-90 hover:opacity-100 hover:border-brand/60 transition-colors";
787
+ removeButton.setAttribute("aria-label", "Remove Header");
788
+ removeButton.setAttribute("title", "Remove Header");
789
+ removeButton.innerHTML =
790
+ '<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 12h12"></path></svg>';
791
+ removeButton.addEventListener("click", () => {
792
+ requestHeaders.splice(index, 1);
793
+ renderHeaderInputs();
794
+ updateRequestPreview();
795
+ });
796
+
797
+ row.appendChild(keyInput);
798
+ row.appendChild(valueInput);
799
+ row.appendChild(removeButton);
800
+ container.appendChild(row);
801
+ });
802
+ }
803
+
804
+ function hasHeaderName(headers, expectedName) {
805
+ const target = expectedName.toLowerCase();
806
+ return Object.keys(headers).some((key) => key.toLowerCase() === target);
807
+ }
808
+
809
+ function getRequestHeadersObject() {
810
+ const headers = {};
811
+ for (const entry of requestHeaders) {
812
+ const key = String(entry.key || "").trim();
813
+ const value = String(entry.value || "").trim();
814
+ if (!key || !value) continue;
815
+ headers[key] = value;
816
+ }
817
+ return headers;
818
+ }
819
+
820
+ function buildCurl(op, headers, body, requestPath) {
821
+ const url = window.location.origin + requestPath;
822
+ const lines = ['curl -X ' + op.method + ' "' + url + '"'];
823
+
824
+ for (const [name, value] of Object.entries(headers)) {
825
+ const safeName = String(name).replace(/"/g, '\\"');
826
+ const safeValue = String(value).replace(/"/g, '\\"');
827
+ lines.push(' -H "' + safeName + ": " + safeValue + '"');
828
+ }
829
+
830
+ if (body) {
831
+ lines.push(" -d '" + body.replace(/'/g, "'\\\\''") + "'");
832
+ }
833
+
834
+ return lines.join(" \\\\\\n");
835
+ }
836
+
837
+ function formatBodyJsonInput() {
838
+ const bodyInput = document.getElementById("body-input");
839
+ if (!bodyInput) return;
840
+ const current = bodyInput.value.trim();
841
+ if (!current) return;
842
+ try {
843
+ bodyInput.value = JSON.stringify(JSON.parse(current), null, 2);
844
+ } catch {}
845
+ }
846
+
847
+ function escapeHtml(value) {
848
+ return String(value)
849
+ .replace(/&/g, "&amp;")
850
+ .replace(/</g, "&lt;")
851
+ .replace(/>/g, "&gt;");
852
+ }
853
+
854
+ function toPrettyJson(value) {
855
+ const trimmed = (value || "").trim();
856
+ if (!trimmed) return null;
857
+ try {
858
+ return JSON.stringify(JSON.parse(trimmed), null, 2);
859
+ } catch {
860
+ return null;
861
+ }
862
+ }
863
+
864
+ function highlightJson(jsonText) {
865
+ const escaped = escapeHtml(jsonText);
866
+ return escaped.replace(
867
+ /("(\\\\u[a-zA-Z0-9]{4}|\\\\[^u]|[^\\\\"])*"(\\s*:)?|\\btrue\\b|\\bfalse\\b|\\bnull\\b|-?\\d+(?:\\.\\d+)?(?:[eE][+\\-]?\\d+)?)/g,
868
+ (match) => {
869
+ let cls = "json-number";
870
+ if (match.startsWith('"')) {
871
+ cls = match.endsWith(":") ? "json-key" : "json-string";
872
+ } else if (match === "true" || match === "false") {
873
+ cls = "json-boolean";
874
+ } else if (match === "null") {
875
+ cls = "json-null";
876
+ }
877
+ return '<span class="' + cls + '">' + match + "</span>";
878
+ },
879
+ );
880
+ }
881
+
882
+ function updateBodyJsonPresentation() {
883
+ const bodyInput = document.getElementById("body-input");
884
+ const highlight = document.getElementById("body-highlight");
885
+ const bodySection = document.getElementById("request-body-section");
886
+
887
+ if (!bodyInput || !highlight || !bodySection) return;
888
+ if (bodySection.classList.contains("hidden")) {
889
+ highlight.innerHTML = "";
890
+ return;
891
+ }
892
+
893
+ const raw = bodyInput.value || "";
894
+ if (!raw.trim()) {
895
+ const placeholder = bodyInput.getAttribute("placeholder") || "";
896
+ highlight.innerHTML = '<span class="opacity-40">' + escapeHtml(placeholder) + "</span>";
897
+ return;
898
+ }
899
+
900
+ const prettyJson = toPrettyJson(raw);
901
+ if (!prettyJson) {
902
+ highlight.innerHTML = escapeHtml(raw);
903
+ return;
904
+ }
905
+
906
+ highlight.innerHTML = highlightJson(raw);
907
+ }
908
+
909
+ function syncBodyEditorScroll() {
910
+ const bodyInput = document.getElementById("body-input");
911
+ const highlight = document.getElementById("body-highlight");
912
+ if (!bodyInput || !highlight) return;
913
+ highlight.scrollTop = bodyInput.scrollTop;
914
+ highlight.scrollLeft = bodyInput.scrollLeft;
915
+ }
916
+
917
+ function updateExpandEditorPresentation() {
918
+ const editor = document.getElementById("expand-editor");
919
+ const highlight = document.getElementById("expand-editor-highlight");
920
+ if (!editor || !highlight) return;
921
+ const raw = editor.value || "";
922
+ if (!raw.trim()) {
923
+ highlight.innerHTML = "";
924
+ return;
925
+ }
926
+ const prettyJson = toPrettyJson(raw);
927
+ highlight.innerHTML = prettyJson ? highlightJson(raw) : escapeHtml(raw);
928
+ }
929
+
930
+ function syncExpandEditorScroll() {
931
+ const editor = document.getElementById("expand-editor");
932
+ const highlight = document.getElementById("expand-editor-highlight");
933
+ if (!editor || !highlight) return;
934
+ highlight.scrollTop = editor.scrollTop;
935
+ highlight.scrollLeft = editor.scrollLeft;
936
+ }
937
+
938
+ function formatResponseText(responseText) {
939
+ const trimmed = (responseText || "").trim();
940
+ if (!trimmed) return { text: "(empty)", isJson: false };
941
+ try {
942
+ return {
943
+ text: JSON.stringify(JSON.parse(trimmed), null, 2),
944
+ isJson: true,
945
+ };
946
+ } catch {
947
+ return {
948
+ text: responseText,
949
+ isJson: false,
950
+ };
951
+ }
952
+ }
953
+
954
+ function setResponseContent(headerText, bodyText, isJson) {
955
+ const result = document.getElementById("result");
956
+ if (!result) return;
957
+ const fullText = String(headerText || "") + String(bodyText || "");
958
+ result.dataset.raw = fullText;
959
+ result.dataset.header = String(headerText || "");
960
+ result.dataset.body = String(bodyText || "");
961
+ result.dataset.isJson = isJson ? "true" : "false";
962
+ if (isJson) {
963
+ result.innerHTML = escapeHtml(String(headerText || "")) + highlightJson(String(bodyText || ""));
964
+ } else {
965
+ result.textContent = fullText;
966
+ }
967
+ }
968
+
969
+ function updateRequestPreview() {
970
+ if (!selected) return;
971
+
972
+ const { path, query } = getOperationParameterGroups(selected);
973
+ const values = getParameterValues(selected);
974
+ const requestPath = buildRequestPath(selected, path, query, values);
975
+ const bodyInput = document.getElementById("body-input");
976
+ const body = bodyInput ? bodyInput.value.trim() : "";
977
+ const headers = getRequestHeadersObject();
978
+ if (body && !hasHeaderName(headers, "Content-Type")) {
979
+ headers["Content-Type"] = "application/json";
980
+ }
981
+
982
+ document.getElementById("endpoint-path").textContent = requestPath;
983
+ document.getElementById("curl-code").textContent = buildCurl(
984
+ selected,
985
+ headers,
986
+ body,
987
+ requestPath,
988
+ );
989
+ }
990
+
991
+ function renderEndpoint() {
992
+ if (!selected) return;
993
+ const endpointCard = document.getElementById("endpoint-card");
994
+ if (endpointCard) {
995
+ endpointCard.classList.remove("enter-fade-up");
996
+ // Restart CSS animation for each operation switch
997
+ void endpointCard.offsetWidth;
998
+ endpointCard.classList.add("enter-fade-up");
999
+ }
1000
+
1001
+ const op = selected.operation || {};
1002
+ const reqSchema = op.requestBody && op.requestBody.content && op.requestBody.content["application/json"] && op.requestBody.content["application/json"].schema;
1003
+ const requestBodySection = document.getElementById("request-body-section");
1004
+ const bodyInput = document.getElementById("body-input");
1005
+ const expandBodyBtn = document.getElementById("expand-body-btn");
1006
+ const supportsBody = hasMeaningfulRequestBodySchema(reqSchema);
1007
+
1008
+ if (requestBodySection) {
1009
+ requestBodySection.classList.toggle("hidden", !supportsBody);
1010
+ }
1011
+ if (supportsBody && bodyInput) {
1012
+ const existingDraft = getBodyDraft(selected);
1013
+ if (typeof existingDraft === "string") {
1014
+ bodyInput.value = existingDraft;
1015
+ } else {
1016
+ const prefill = buildRequiredBodyPrefill(reqSchema);
1017
+ bodyInput.value = prefill;
1018
+ setBodyDraft(selected, prefill);
1019
+ }
1020
+ } else if (!supportsBody && bodyInput) {
1021
+ bodyInput.value = "";
1022
+ }
1023
+ if (expandBodyBtn) {
1024
+ expandBodyBtn.disabled = !supportsBody;
1025
+ }
1026
+ setResponseContent("", "", false);
1027
+
1028
+ document.getElementById("tag-title").textContent = selected.tag;
1029
+ document.getElementById("tag-description").textContent = op.description || "Interactive API documentation.";
1030
+ const methodNode = document.getElementById("endpoint-method");
1031
+ methodNode.textContent = selected.method;
1032
+ methodNode.className = "px-2.5 py-0.5 rounded-full text-xs font-mono font-medium " + (methodBadge[selected.method] || "bg-zinc-100 text-zinc-700 dark:bg-zinc-500/10 dark:text-zinc-400");
1033
+ document.getElementById("endpoint-title").textContent = selected.name;
1034
+ document.getElementById("endpoint-path").textContent = selected.path;
1035
+
1036
+ const { all: params, query, path, headers } =
1037
+ getOperationParameterGroups(selected);
1038
+
1039
+ let html = "";
1040
+ html += renderParamSection("Path Parameters", path);
1041
+ html += renderParamSection("Query Parameters", query);
1042
+ html += renderParamSection("Header Parameters", headers);
1043
+
1044
+ html += renderRequestBodySchemaSection(reqSchema);
1045
+ document.getElementById("params-column").innerHTML = html || '<div class="text-sm opacity-70">No parameters</div>';
1046
+ renderTryItParameterInputs(path, query);
1047
+ renderHeaderInputs();
1048
+ updateRequestPreview();
1049
+ updateBodyJsonPresentation();
1050
+ syncBodyEditorScroll();
1051
+ }
1052
+
1053
+ document.getElementById("copy-curl").addEventListener("click", async () => {
1054
+ try { await navigator.clipboard.writeText(document.getElementById("curl-code").textContent || ""); } catch {}
1055
+ });
1056
+ document.getElementById("sidebar-search").addEventListener("input", (event) => {
1057
+ sidebarSearchQuery = event.currentTarget.value || "";
1058
+ renderSidebar();
1059
+ });
1060
+
1061
+ document.getElementById("send-btn").addEventListener("click", async () => {
1062
+ if (!selected) return;
1063
+ const { path, query } = getOperationParameterGroups(selected);
1064
+ const values = getParameterValues(selected);
1065
+ const missingPathParams = path.filter((param) => {
1066
+ if (param.required === false) return false;
1067
+ const value = values[param.name];
1068
+ return value === undefined || value === null || String(value).trim() === "";
1069
+ });
1070
+
1071
+ if (missingPathParams.length > 0) {
1072
+ setResponseContent(
1073
+ "",
1074
+ "Missing required path parameter(s): " +
1075
+ missingPathParams.map((param) => param.name).join(", "),
1076
+ false,
1077
+ );
1078
+ return;
1079
+ }
1080
+
1081
+ const requestPath = buildRequestPath(selected, path, query, values);
1082
+ formatBodyJsonInput();
1083
+ updateBodyJsonPresentation();
1084
+ const op = selected.operation || {};
1085
+ const reqSchema = op.requestBody && op.requestBody.content && op.requestBody.content["application/json"] && op.requestBody.content["application/json"].schema;
1086
+ const supportsBody = hasMeaningfulRequestBodySchema(reqSchema);
1087
+ const bodyInput = document.getElementById("body-input");
1088
+ const body =
1089
+ supportsBody && bodyInput ? bodyInput.value.trim() : "";
1090
+ const headers = getRequestHeadersObject();
1091
+ if (body && !hasHeaderName(headers, "Content-Type")) {
1092
+ headers["Content-Type"] = "application/json";
1093
+ }
1094
+
1095
+ try {
1096
+ const response = await fetch(requestPath, { method: selected.method, headers, body: body || undefined });
1097
+ const text = await response.text();
1098
+ const contentType = response.headers.get("content-type") || "unknown";
1099
+ const formattedResponse = formatResponseText(text);
1100
+ const headerText =
1101
+ "Status: " + response.status + " " + response.statusText + "\\n" +
1102
+ "Content-Type: " + contentType + "\\n\\n";
1103
+ setResponseContent(
1104
+ headerText,
1105
+ formattedResponse.text,
1106
+ formattedResponse.isJson,
1107
+ );
1108
+ } catch (error) {
1109
+ setResponseContent("", "Request failed: " + String(error), false);
1110
+ }
1111
+ });
1112
+
1113
+ function openExpandModal(mode) {
1114
+ const modal = document.getElementById("expand-modal");
1115
+ const title = document.getElementById("expand-modal-title");
1116
+ const editorShell = document.getElementById("expand-editor-shell");
1117
+ const editor = document.getElementById("expand-editor");
1118
+ const viewer = document.getElementById("expand-viewer");
1119
+ const apply = document.getElementById("expand-apply");
1120
+ const bodyInput = document.getElementById("body-input");
1121
+ const result = document.getElementById("result");
1122
+ if (!modal || !title || !editorShell || !editor || !viewer || !apply) return;
1123
+
1124
+ expandModalMode = mode;
1125
+ modal.classList.remove("hidden");
1126
+ modal.classList.add("flex");
1127
+
1128
+ if (mode === "body") {
1129
+ title.textContent = "Request Body";
1130
+ editorShell.classList.remove("hidden");
1131
+ viewer.classList.add("hidden");
1132
+ apply.classList.remove("hidden");
1133
+ editor.value = bodyInput ? bodyInput.value : "";
1134
+ updateExpandEditorPresentation();
1135
+ syncExpandEditorScroll();
1136
+ } else {
1137
+ title.textContent = "Response";
1138
+ viewer.classList.remove("hidden");
1139
+ editorShell.classList.add("hidden");
1140
+ apply.classList.add("hidden");
1141
+ const hasResponse = Boolean(result && result.dataset && result.dataset.raw);
1142
+ if (!hasResponse) {
1143
+ viewer.textContent = "(empty response yet)";
1144
+ return;
1145
+ }
1146
+
1147
+ const header = result.dataset.header || "";
1148
+ const body = result.dataset.body || "";
1149
+ const isJson = result.dataset.isJson === "true";
1150
+ if (isJson) {
1151
+ viewer.innerHTML = escapeHtml(header) + highlightJson(body);
1152
+ } else {
1153
+ viewer.textContent = result.dataset.raw || "(empty response yet)";
1154
+ }
1155
+ }
1156
+ }
1157
+
1158
+ function closeExpandModal() {
1159
+ const modal = document.getElementById("expand-modal");
1160
+ if (!modal) return;
1161
+ modal.classList.add("hidden");
1162
+ modal.classList.remove("flex");
1163
+ expandModalMode = null;
1164
+ }
1165
+
1166
+ document.getElementById("add-header-btn").addEventListener("click", () => {
1167
+ requestHeaders.push({ key: "", value: "" });
1168
+ renderHeaderInputs();
1169
+ updateRequestPreview();
1170
+ });
1171
+ document.getElementById("body-input").addEventListener("input", () => {
1172
+ if (selected) {
1173
+ setBodyDraft(selected, document.getElementById("body-input").value);
1174
+ }
1175
+ updateRequestPreview();
1176
+ updateBodyJsonPresentation();
1177
+ syncBodyEditorScroll();
1178
+ });
1179
+ document.getElementById("body-input").addEventListener("scroll", () => {
1180
+ syncBodyEditorScroll();
1181
+ });
1182
+ document.getElementById("body-input").addEventListener("keydown", (event) => {
1183
+ if (event.key !== "Tab") return;
1184
+ event.preventDefault();
1185
+ const input = event.currentTarget;
1186
+ const start = input.selectionStart;
1187
+ const end = input.selectionEnd;
1188
+ const value = input.value;
1189
+ const tab = " ";
1190
+ input.value = value.slice(0, start) + tab + value.slice(end);
1191
+ input.selectionStart = input.selectionEnd = start + tab.length;
1192
+ if (selected) {
1193
+ setBodyDraft(selected, input.value);
1194
+ }
1195
+ updateRequestPreview();
1196
+ updateBodyJsonPresentation();
1197
+ syncBodyEditorScroll();
1198
+ });
1199
+ document.getElementById("body-input").addEventListener("blur", () => {
1200
+ formatBodyJsonInput();
1201
+ if (selected) {
1202
+ setBodyDraft(selected, document.getElementById("body-input").value);
1203
+ }
1204
+ updateRequestPreview();
1205
+ updateBodyJsonPresentation();
1206
+ syncBodyEditorScroll();
1207
+ });
1208
+ document.getElementById("expand-editor").addEventListener("input", () => {
1209
+ updateExpandEditorPresentation();
1210
+ syncExpandEditorScroll();
1211
+ });
1212
+ document.getElementById("expand-editor").addEventListener("scroll", () => {
1213
+ syncExpandEditorScroll();
1214
+ });
1215
+ document.getElementById("expand-editor").addEventListener("keydown", (event) => {
1216
+ if (event.key !== "Tab") return;
1217
+ event.preventDefault();
1218
+ const editor = event.currentTarget;
1219
+ const start = editor.selectionStart;
1220
+ const end = editor.selectionEnd;
1221
+ const value = editor.value;
1222
+ const tab = " ";
1223
+ editor.value = value.slice(0, start) + tab + value.slice(end);
1224
+ editor.selectionStart = editor.selectionEnd = start + tab.length;
1225
+ updateExpandEditorPresentation();
1226
+ syncExpandEditorScroll();
1227
+ });
1228
+ document.getElementById("expand-editor").addEventListener("blur", () => {
1229
+ const editor = document.getElementById("expand-editor");
1230
+ const current = editor.value.trim();
1231
+ if (current) {
1232
+ try {
1233
+ editor.value = JSON.stringify(JSON.parse(current), null, 2);
1234
+ } catch {}
1235
+ }
1236
+ updateExpandEditorPresentation();
1237
+ syncExpandEditorScroll();
1238
+ });
1239
+ document.getElementById("expand-body-btn").addEventListener("click", () => {
1240
+ openExpandModal("body");
1241
+ });
1242
+ document.getElementById("expand-response-btn").addEventListener("click", () => {
1243
+ openExpandModal("response");
1244
+ });
1245
+ document.getElementById("expand-close").addEventListener("click", closeExpandModal);
1246
+ document.getElementById("expand-apply").addEventListener("click", () => {
1247
+ if (expandModalMode !== "body") {
1248
+ closeExpandModal();
1249
+ return;
1250
+ }
1251
+
1252
+ const editor = document.getElementById("expand-editor");
1253
+ const bodyInput = document.getElementById("body-input");
1254
+ if (editor && bodyInput) {
1255
+ bodyInput.value = editor.value;
1256
+ formatBodyJsonInput();
1257
+ if (selected) {
1258
+ setBodyDraft(selected, bodyInput.value);
1259
+ }
1260
+ updateRequestPreview();
1261
+ updateBodyJsonPresentation();
1262
+ syncBodyEditorScroll();
1263
+ }
1264
+ closeExpandModal();
1265
+ });
1266
+ document.getElementById("expand-modal").addEventListener("click", (event) => {
1267
+ if (event.target === event.currentTarget) {
1268
+ closeExpandModal();
1269
+ }
1270
+ });
1271
+ document.getElementById("sidebar-open").addEventListener("click", () => {
1272
+ setMobileSidebarOpen(true);
1273
+ });
1274
+ document.getElementById("sidebar-close").addEventListener("click", () => {
1275
+ setMobileSidebarOpen(false);
1276
+ });
1277
+ document.getElementById("mobile-backdrop").addEventListener("click", () => {
1278
+ setMobileSidebarOpen(false);
1279
+ });
1280
+ window.addEventListener("resize", () => {
1281
+ if (window.innerWidth >= 768 && isMobileSidebarOpen) {
1282
+ setMobileSidebarOpen(false);
1283
+ }
1284
+ });
1285
+ document.addEventListener("keydown", (event) => {
1286
+ if (event.key === "Escape") {
1287
+ if (isMobileSidebarOpen) {
1288
+ setMobileSidebarOpen(false);
1289
+ }
1290
+ closeExpandModal();
1291
+ }
1292
+ });
1293
+
1294
+ const themeToggleBtn = document.getElementById('theme-toggle');
1295
+ const htmlElement = document.documentElement;
1296
+ themeToggleBtn.addEventListener('click', () => {
1297
+ htmlElement.classList.toggle('dark');
1298
+ if (htmlElement.classList.contains('dark')) {
1299
+ localStorage.setItem('theme', 'dark');
1300
+ } else {
1301
+ localStorage.setItem('theme', 'light');
1302
+ }
1303
+ });
1304
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
1305
+ if (!('theme' in localStorage)) {
1306
+ if (e.matches) htmlElement.classList.add('dark');
1307
+ else htmlElement.classList.remove('dark');
1308
+ }
1309
+ });
1310
+
1311
+ setMobileSidebarOpen(false);
1312
+ renderSidebar();
1313
+ renderEndpoint();
1314
+ </script>
1315
+ </body>
1316
+ </html>`;
1317
+ }