This commit is contained in:
186
src/templates/html_template.html
Normal file
186
src/templates/html_template.html
Normal file
@@ -0,0 +1,186 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ title }} - API Documentation</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #333; display: flex; }
|
||||
.sidebar { width: 280px; background: #1a1a2e; color: #fff; height: 100vh; position: fixed; overflow-y: auto; padding: 20px 0; }
|
||||
.sidebar-header { padding: 0 20px 20px; border-bottom: 1px solid #2d2d44; margin-bottom: 20px; }
|
||||
.sidebar-header h1 { font-size: 18px; font-weight: 600; }
|
||||
.sidebar-header p { font-size: 12px; color: #888; margin-top: 5px; }
|
||||
.nav-section { margin-bottom: 20px; }
|
||||
.nav-section h3 { font-size: 11px; text-transform: uppercase; color: #666; padding: 0 20px; margin-bottom: 10px; letter-spacing: 1px; }
|
||||
.nav-item { display: block; padding: 8px 20px; color: #ccc; text-decoration: none; font-size: 14px; cursor: pointer; }
|
||||
.nav-item:hover { background: #2d2d44; color: #fff; }
|
||||
.nav-item.active { background: #2d2d44; color: #4f8cff; border-left: 3px solid #4f8cff; }
|
||||
.method-badge { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 11px; font-weight: 600; margin-right: 8px; }
|
||||
.method-GET { background: #e3f2fd; color: #1976d2; }
|
||||
.method-POST { background: #e8f5e9; color: #388e3c; }
|
||||
.method-PUT { background: #fff3e0; color: #f57c00; }
|
||||
.method-DELETE { background: #ffebee; color: #d32f2f; }
|
||||
.method-PATCH { background: #f3e5f5; color: #7b1fa2; }
|
||||
.main-content { margin-left: 280px; flex: 1; padding: 40px; max-width: 900px; }
|
||||
.endpoint-header { margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid #eee; }
|
||||
.endpoint-title { font-size: 24px; font-weight: 600; margin-bottom: 10px; }
|
||||
.endpoint-path { font-family: monospace; font-size: 16px; color: #e91e63; background: #fce4ec; padding: 8px 12px; border-radius: 4px; display: inline-block; }
|
||||
.section { margin-bottom: 30px; }
|
||||
.section h2 { font-size: 18px; font-weight: 600; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #eee; }
|
||||
.param-table { width: 100%; border-collapse: collapse; }
|
||||
.param-table th, .param-table td { text-align: left; padding: 12px; border-bottom: 1px solid #eee; }
|
||||
.param-table th { background: #f8f9fa; font-weight: 600; font-size: 13px; }
|
||||
.param-name { font-family: monospace; font-weight: 600; }
|
||||
.param-type { color: #666; font-size: 13px; }
|
||||
.param-required { color: #d32f2f; font-size: 12px; }
|
||||
.code-block { background: #1a1a2e; color: #f8f8f2; padding: 20px; border-radius: 8px; overflow-x: auto; font-family: 'Monaco', 'Consolas', monospace; font-size: 13px; line-height: 1.5; }
|
||||
.code-block .string { color: #a6e22e; }
|
||||
.code-block .number { color: #ae81ff; }
|
||||
.code-block .boolean { color: #f92672; }
|
||||
.code-block .null { color: #f8f8f2; }
|
||||
.code-block .key { color: #66d9ef; }
|
||||
.tag-badge { display: inline-block; background: #e3f2fd; color: #1976d2; padding: 4px 10px; border-radius: 12px; font-size: 12px; margin-right: 5px; }
|
||||
.deprecated-badge { background: #fff3e0; color: #f57c00; padding: 4px 10px; border-radius: 12px; font-size: 12px; }
|
||||
.response-badge { display: inline-block; padding: 6px 12px; border-radius: 4px; font-size: 13px; margin-right: 10px; }
|
||||
.response-2xx { background: #e8f5e9; color: #388e3c; }
|
||||
.response-4xx { background: #ffebee; color: #d32f2f; }
|
||||
.response-5xx { background: #fff3e0; color: #f57c00; }
|
||||
.search-box { margin: 0 20px 20px; }
|
||||
.search-box input { width: 100%; padding: 10px 15px; border: none; border-radius: 6px; background: #2d2d44; color: #fff; font-size: 14px; }
|
||||
.search-box input::placeholder { color: #888; }
|
||||
.search-results { display: none; }
|
||||
.search-results.active { display: block; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h1>{{ title }}</h1>
|
||||
<p>Version {{ version }}</p>
|
||||
</div>
|
||||
<div class="search-box">
|
||||
<input type="text" id="searchInput" placeholder="Search endpoints..." onkeyup="filterEndpoints()">
|
||||
</div>
|
||||
<div class="nav-section">
|
||||
<h3>Endpoints</h3>
|
||||
{% for endpoint in endpoints %}
|
||||
<a class="nav-item" href="#{{ endpoint.method }}-{{ endpoint.path|replace('/', '_')|replace('{', '')|replace('}', '') }}" onclick="showEndpoint('{{ endpoint.method }}-{{ endpoint.path|replace('/', '_')|replace('{', '')|replace('}', '') }}')">
|
||||
<span class="method-badge method-{{ endpoint.method }}">{{ endpoint.method }}</span>
|
||||
<span>{{ endpoint.path }}</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="main-content">
|
||||
{% for endpoint in endpoints %}
|
||||
<div id="{{ endpoint.method }}-{{ endpoint.path|replace('/', '_')|replace('{', '')|replace('}', '') }}" class="endpoint-section">
|
||||
<div class="endpoint-header">
|
||||
<div class="endpoint-title">{{ endpoint.summary or endpoint.description or 'Endpoint' }}</div>
|
||||
<div class="endpoint-path">
|
||||
<span class="method-badge method-{{ endpoint.method }}">{{ endpoint.method }}</span>
|
||||
{{ endpoint.path }}
|
||||
</div>
|
||||
{% if endpoint.deprecated %}
|
||||
<span class="deprecated-badge" style="margin-top: 10px; display: inline-block;">Deprecated</span>
|
||||
{% endif %}
|
||||
{% if endpoint.tags %}
|
||||
<div style="margin-top: 15px;">
|
||||
{% for tag in endpoint.tags %}
|
||||
<span class="tag-badge">{{ tag }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if endpoint.description %}
|
||||
<div class="section">
|
||||
<h2>Description</h2>
|
||||
<p>{{ endpoint.description }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if endpoint.parameters and endpoint.parameters|length > 0 %}
|
||||
<div class="section">
|
||||
<h2>Parameters</h2>
|
||||
<table class="param-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Location</th>
|
||||
<th>Description</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for param in endpoint.parameters %}
|
||||
<tr>
|
||||
<td>
|
||||
<span class="param-name">{{ param.name }}</span>
|
||||
{% if param.required %}<span class="param-required">*</span>{% endif %}
|
||||
</td>
|
||||
<td class="param-type">{{ param.schema.type if param.schema else 'any' }}</td>
|
||||
<td class="param-type">{{ param.in }}</td>
|
||||
<td>{{ param.description or '-' }}</td>
|
||||
<td>{% if param.required %}<span class="param-required">required</span>{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if endpoint.request_body %}
|
||||
<div class="section">
|
||||
<h2>Request Body</h2>
|
||||
<pre class="code-block"><code>{{ endpoint.request_body|tojson(indent=2) }}</code></pre>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="section">
|
||||
<h2>Responses</h2>
|
||||
{% for status, response in endpoint.responses.items() %}
|
||||
<div style="margin-bottom: 20px;">
|
||||
{% if status|startswith('2') %}
|
||||
<span class="response-badge response-2xx">{{ status }}</span>
|
||||
{% elif status|startswith('4') %}
|
||||
<span class="response-badge response-4xx">{{ status }}</span>
|
||||
{% elif status|startswith('5') %}
|
||||
<span class="response-badge response-5xx">{{ status }}</span>
|
||||
{% else %}
|
||||
<span class="response-badge">{{ status }}</span>
|
||||
{% endif %}
|
||||
<span>{{ response.description if response.description else '' }}</span>
|
||||
{% if response.content and response.content.get('application/json') %}
|
||||
<pre class="code-block" style="margin-top: 10px;"><code>{{ response.content['application/json'].schema|tojson(indent=2) }}</code></pre>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<hr style="margin: 40px 0; border: none; border-top: 1px solid #eee;">
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function showEndpoint(id) {
|
||||
document.querySelectorAll('.endpoint-section').forEach(el => el.style.display = 'none');
|
||||
const target = document.getElementById(id);
|
||||
if (target) target.style.display = 'block';
|
||||
document.querySelectorAll('.nav-item').forEach(el => el.classList.remove('active'));
|
||||
event.target.closest('.nav-item').classList.add('active');
|
||||
}
|
||||
|
||||
function filterEndpoints() {
|
||||
const query = document.getElementById('searchInput').value.toLowerCase();
|
||||
document.querySelectorAll('.nav-item').forEach(item => {
|
||||
const text = item.textContent.toLowerCase();
|
||||
item.style.display = text.includes(query) ? 'block' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelector('.nav-item').click();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user