-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
361 lines (330 loc) · 11.3 KB
/
index.html
File metadata and controls
361 lines (330 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>API Documentation</title>
<link rel="icon" href="https://cloudinary-res.cloudinary.com/image/upload/f_auto,q_auto,w_32/website/cloudinary_web_favicon.png">
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/dist/js-yaml.min.js"></script>
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css">
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css">
<style>
body {
font-family: 'Inter', sans-serif;
margin: 0;
padding-top: 70px;
background-color: #f8fafc;
color: #2d3748;
}
header {
background-color: #ffffff;
padding: 10px 20px;
border-bottom: 1px solid #e2e8f0;
display: flex;
align-items: center;
justify-content: space-between;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
header img {
height: 32px;
}
nav button {
margin-right: 8px;
padding: 6px 12px;
background-color: transparent;
border: none;
color: #4a5568;
cursor: pointer;
border-radius: 4px;
}
nav button.active, nav button:hover {
background-color: #007bff;
color: white;
}
nav select {
padding: 8px 35px 8px 16px;
border-radius: 6px;
border: 2px solid #007bff;
background-color: white;
color: #007bff;
font-weight: 500;
font-size: 14px;
appearance: none;
background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="%23007bff"><polygon points="0,0 12,0 6,8"/></svg>');
background-repeat: no-repeat;
background-position: right 12px top 50%;
background-size: 12px;
cursor: pointer;
margin-left: 10px;
transition: all 0.2s;
}
nav select:hover {
background-color: #007bff;
color: white;
background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="white"><polygon points="0,0 12,0 6,8"/></svg>');
}
nav select:focus {
outline: none;
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}
#viewer-container {
padding: 20px;
}
@media (max-width: 768px) {
header {
flex-direction: column;
align-items: flex-start;
padding-bottom: 15px;
}
nav {
display: flex;
overflow-x: auto;
width: 100%;
padding-bottom: 8px;
}
nav button {
white-space: nowrap;
}
header > div {
width: 100%;
justify-content: space-between;
margin-top: 10px;
flex-wrap: wrap;
gap: 10px;
}
header > div a {
order: 1;
flex-shrink: 0;
}
nav select {
margin-left: 0;
order: 2;
flex: 1;
min-width: 120px;
}
header img {
margin-top: 0;
order: 3;
flex-shrink: 0;
}
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
</head>
<body>
<header>
<nav id="nav-container"></nav>
<div style="display: flex; align-items: center; gap: 15px;">
<a href="#" id="mcp-analyzer-link" style="background-color: #28a745; color: white; padding: 8px 16px; border-radius: 6px; text-decoration: none; font-weight: 500; font-size: 14px; transition: background-color 0.2s;"
onmouseover="this.style.backgroundColor='#218838'"
onmouseout="this.style.backgroundColor='#28a745'"
onclick="navigateToMCPAnalyzer(event)">
🔍 MCP Analyzer
</a>
<select id="viewer-select">
<option value="redoc">Redocly</option>
<option value="swagger">Swagger UI</option>
<option value="stoplight" selected>Stoplight Elements</option>
</select>
<img src="https://res.cloudinary.com/cloudinary/images/cloudinary_logo_for_white_bg/cloudinary_logo_for_white_bg.png?_i=AA" alt="Cloudinary" style="margin-left: 0;">
</div>
</header>
<div id="viewer-container"></div>
<script>
let currentSchemaPath = '';
async function fetchYaml(path) {
const response = await fetch(path);
const text = await response.text();
return jsyaml.load(text);
}
async function loadSchemasConfig() {
const response = await fetch('schemas.yml');
const yamlText = await response.text();
return jsyaml.load(yamlText).schemas;
}
async function renderNavButtons(schemaDirs) {
const nav = document.getElementById('nav-container');
for (const dir of schemaDirs) {
const schemaPath = `${dir}/schema.yml`;
const schemaContent = await fetchYaml(schemaPath);
const button = document.createElement('button');
button.innerText = schemaContent.info.title || dir;
button.dataset.schemaDir = dir; // Store schema directory for URL persistence
button.onclick = () => {
currentSchemaPath = schemaPath;
renderViewer();
setActiveButton(button);
};
nav.appendChild(button);
}
}
document.getElementById('viewer-select').onchange = renderViewer;
// URL parameter management
function updateURL(schemaDir, viewer) {
const url = new URL(window.location);
if (schemaDir) {
url.searchParams.set('schema', schemaDir);
} else {
url.searchParams.delete('schema');
}
if (viewer) {
url.searchParams.set('viewer', viewer);
} else {
url.searchParams.delete('viewer');
}
window.history.replaceState({}, '', url);
}
function getParametersFromURL() {
const urlParams = new URLSearchParams(window.location.search);
return {
schema: urlParams.get('schema'),
viewer: urlParams.get('viewer')
};
}
// State preservation functions
function saveState() {
// Extract schema directory name for cross-page compatibility
const schemaDir = currentSchemaPath ? currentSchemaPath.split('/')[0] : '';
const viewer = document.getElementById('viewer-select').value;
const state = {
selectedSchema: currentSchemaPath,
selectedSchemaDir: schemaDir, // Add normalized identifier
selectedViewer: viewer,
timestamp: Date.now()
};
localStorage.setItem('api-docs-state', JSON.stringify(state));
// Also save to shared state for MCP viewer
localStorage.setItem('shared-schema-state', JSON.stringify({
activeSchemaDir: schemaDir,
timestamp: Date.now()
}));
// Update URL to reflect current state
updateURL(schemaDir, viewer);
}
function loadState() {
try {
const saved = localStorage.getItem('api-docs-state');
let state = null;
if (saved) {
state = JSON.parse(saved);
// Only use if saved within last 24 hours
if (Date.now() - state.timestamp >= 24 * 60 * 60 * 1000) {
state = null;
}
}
// Check for shared state from MCP viewer (higher priority)
const sharedState = localStorage.getItem('shared-schema-state');
if (sharedState) {
const shared = JSON.parse(sharedState);
if (Date.now() - shared.timestamp < 24 * 60 * 60 * 1000) {
// Override schema selection with shared state
if (!state) state = {};
state.selectedSchemaDir = shared.activeSchemaDir;
}
}
return state;
} catch (e) {
console.warn('Could not load saved state:', e);
}
return null;
}
function setActiveButton(activeButton) {
document.querySelectorAll('nav button').forEach(btn => btn.classList.remove('active'));
activeButton.classList.add('active');
saveState(); // Save state when schema changes
}
function navigateToMCPAnalyzer(event) {
event.preventDefault();
const schemaDir = currentSchemaPath ? currentSchemaPath.split('/')[0] : '';
let url = 'mcp-operations-viewer.html';
if (schemaDir) {
url += `?schema=${schemaDir}`;
}
window.location.href = url;
}
function renderViewer() {
const viewerType = document.getElementById('viewer-select').value;
const container = document.getElementById('viewer-container');
container.innerHTML = '';
if (viewerType === 'redoc') {
Redoc.init(currentSchemaPath, {}, container);
} else if (viewerType === 'swagger') {
SwaggerUIBundle({
url: currentSchemaPath,
dom_id: '#viewer-container'
});
} else if (viewerType === 'stoplight') {
const el = document.createElement('elements-api');
el.setAttribute('apiDescriptionUrl', currentSchemaPath);
el.setAttribute('router', 'hash');
container.appendChild(el);
}
saveState(); // Save state when viewer changes
}
(async () => {
const schemaDirs = await loadSchemasConfig();
await renderNavButtons(schemaDirs);
// Get URL parameters first (highest priority)
const urlParams = getParametersFromURL();
// Try to restore saved state
const savedState = loadState();
let initialSchema = schemaDirs.length > 0 ? `${schemaDirs[0]}/schema.yml` : '';
let initialViewer = 'stoplight';
// Priority order: URL parameters > saved state > defaults
// Determine initial viewer
if (urlParams.viewer) {
// URL parameter takes highest priority
document.getElementById('viewer-select').value = urlParams.viewer;
initialViewer = urlParams.viewer;
console.log('Viewer selected from URL:', urlParams.viewer);
} else if (savedState && savedState.selectedViewer) {
// Saved state second priority
document.getElementById('viewer-select').value = savedState.selectedViewer;
initialViewer = savedState.selectedViewer;
}
// Determine initial schema
if (urlParams.schema) {
// URL parameter takes highest priority
const matchingSchema = schemaDirs.find(dir => dir === urlParams.schema);
if (matchingSchema) {
initialSchema = `${matchingSchema}/schema.yml`;
console.log('Schema selected from URL:', urlParams.schema);
}
} else if (savedState) {
// Saved state second priority - prioritize shared state
const targetSchemaDir = savedState.selectedSchemaDir || savedState.selectedSchema?.split('/')[0];
if (targetSchemaDir) {
const matchingSchema = schemaDirs.find(dir => dir === targetSchemaDir);
if (matchingSchema) {
initialSchema = `${matchingSchema}/schema.yml`;
}
}
}
if (initialSchema) {
currentSchemaPath = initialSchema;
renderViewer();
// Set the active button based on the restored schema
setTimeout(() => {
const buttons = document.querySelectorAll('nav button');
const targetSchemaDir = initialSchema.split('/')[0];
const targetButton = Array.from(buttons).find(btn =>
btn.dataset.schemaDir === targetSchemaDir
);
if (targetButton) {
setActiveButton(targetButton);
} else if (buttons.length > 0) {
setActiveButton(buttons[0]);
}
}, 100);
}
})();
</script>
</body>
</html>