974 lines
31 KiB
HTML
974 lines
31 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>API Documentation - Password Generator</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;
|
|
background: #f5f5f5;
|
|
}
|
|
|
|
.header {
|
|
background: white;
|
|
padding: 20px 0;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.header .container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 0 20px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.header h1 {
|
|
color: #2c3e50;
|
|
font-size: 2rem;
|
|
}
|
|
|
|
.header .nav-links {
|
|
display: flex;
|
|
gap: 20px;
|
|
align-items: center;
|
|
}
|
|
|
|
.header .nav-links a {
|
|
color: #3498db;
|
|
text-decoration: none;
|
|
font-weight: 500;
|
|
padding: 8px 16px;
|
|
border-radius: 5px;
|
|
transition: background-color 0.2s ease;
|
|
}
|
|
|
|
.header .nav-links a:hover {
|
|
background: #ecf0f1;
|
|
}
|
|
|
|
.main-container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 0 20px;
|
|
}
|
|
|
|
.intro-section {
|
|
background: white;
|
|
padding: 30px;
|
|
margin-bottom: 30px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.intro-section h2 {
|
|
color: #2c3e50;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.intro-section p {
|
|
color: #7f8c8d;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.base-url {
|
|
background: #3498db;
|
|
color: white;
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
text-align: center;
|
|
margin: 20px 0;
|
|
font-family: monospace;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.downloads-section {
|
|
background: white;
|
|
padding: 30px;
|
|
margin-bottom: 30px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.downloads-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
gap: 20px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.download-card {
|
|
background: #f8f9fa;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 8px;
|
|
padding: 20px;
|
|
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
|
}
|
|
|
|
.download-card:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.download-card h4 {
|
|
color: #2c3e50;
|
|
margin-bottom: 10px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.download-card .icon {
|
|
font-size: 1.5rem;
|
|
}
|
|
|
|
.download-card p {
|
|
color: #7f8c8d;
|
|
font-size: 14px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.download-btn {
|
|
display: inline-block;
|
|
background: #3498db;
|
|
color: white;
|
|
text-decoration: none;
|
|
padding: 10px 20px;
|
|
border-radius: 5px;
|
|
font-weight: 500;
|
|
transition: background-color 0.2s ease;
|
|
}
|
|
|
|
.download-btn:hover {
|
|
background: #2980b9;
|
|
}
|
|
|
|
.swagger-container {
|
|
background: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
overflow: hidden;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.swagger-header {
|
|
background: #34495e;
|
|
color: white;
|
|
padding: 20px 30px;
|
|
}
|
|
|
|
.swagger-header h3 {
|
|
margin: 0;
|
|
font-size: 1.3rem;
|
|
}
|
|
|
|
.swagger-content {
|
|
padding: 0;
|
|
}
|
|
|
|
#swagger-ui {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
|
}
|
|
|
|
.method-tag {
|
|
display: inline-block;
|
|
padding: 4px 8px;
|
|
border-radius: 3px;
|
|
font-size: 12px;
|
|
font-weight: bold;
|
|
text-transform: uppercase;
|
|
margin-right: 10px;
|
|
}
|
|
|
|
.method-get { background: #27ae60; color: white; }
|
|
.method-post { background: #e74c3c; color: white; }
|
|
.method-put { background: #f39c12; color: white; }
|
|
.method-delete { background: #e67e22; color: white; }
|
|
|
|
.features-section {
|
|
background: white;
|
|
padding: 30px;
|
|
margin-bottom: 30px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.features-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
|
gap: 20px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.feature-item {
|
|
padding: 20px;
|
|
border-left: 4px solid #3498db;
|
|
background: #f8f9fa;
|
|
border-radius: 0 5px 5px 0;
|
|
}
|
|
|
|
.feature-item h4 {
|
|
color: #2c3e50;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.feature-item p {
|
|
color: #7f8c8d;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.code-example {
|
|
background: #2c3e50;
|
|
color: #ecf0f1;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 14px;
|
|
overflow-x: auto;
|
|
margin: 15px 0;
|
|
}
|
|
|
|
.copy-btn {
|
|
background: #34495e;
|
|
color: white;
|
|
border: none;
|
|
padding: 5px 10px;
|
|
border-radius: 3px;
|
|
cursor: pointer;
|
|
float: right;
|
|
font-size: 12px;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.copy-btn:hover {
|
|
background: #2c3e50;
|
|
}
|
|
|
|
.footer {
|
|
margin-top: 60px;
|
|
padding: 40px 0;
|
|
background: white;
|
|
border-top: 1px solid #ecf0f1;
|
|
text-align: center;
|
|
color: #7f8c8d;
|
|
}
|
|
|
|
.footer a {
|
|
color: #3498db;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.footer a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.notification {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
padding: 15px 20px;
|
|
background: #27ae60;
|
|
color: white;
|
|
border-radius: 5px;
|
|
font-weight: 500;
|
|
z-index: 1000;
|
|
transform: translateX(100%);
|
|
transition: transform 0.3s ease;
|
|
}
|
|
|
|
.notification.show {
|
|
transform: translateX(0);
|
|
}
|
|
|
|
/* Swagger UI Customizations */
|
|
.swagger-ui .info .title {
|
|
color: #2c3e50;
|
|
}
|
|
|
|
.swagger-ui .scheme-container {
|
|
background: #f8f9fa;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 5px;
|
|
padding: 10px;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.swagger-ui .info .description {
|
|
color: #7f8c8d;
|
|
}
|
|
|
|
.swagger-ui .opblock.opblock-get .opblock-summary-method {
|
|
background: #27ae60;
|
|
}
|
|
|
|
.swagger-ui .opblock.opblock-post .opblock-summary-method {
|
|
background: #e74c3c;
|
|
}
|
|
|
|
.swagger-ui .opblock-tag {
|
|
color: #2c3e50;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.header .container {
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
|
|
.downloads-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.features-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|
|
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui.css" />
|
|
</head>
|
|
<body>
|
|
<header class="header">
|
|
<div class="container">
|
|
<h1>🔐 Password Generator API</h1>
|
|
<nav class="nav-links">
|
|
<a href="/">← Back to Generator</a>
|
|
</nav>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="main-container">
|
|
<div class="intro-section">
|
|
<h2>API Documentation</h2>
|
|
<p>Complete OpenAPI 3.0 specification for the Password Generator API. Generate secure passwords with multiple algorithms, manage wordlists dynamically, and support international languages.</p>
|
|
|
|
<div class="base-url">
|
|
Base URL: <code>http://localhost:8080/api/v1</code>
|
|
</div>
|
|
|
|
<div class="features-grid">
|
|
<div class="feature-item">
|
|
<h4>🔐 Multiple Algorithms</h4>
|
|
<p>High-entropy, XKCD, Diceware, PWGen, and Passkey generation methods</p>
|
|
</div>
|
|
<div class="feature-item">
|
|
<h4>🌍 Internationalization</h4>
|
|
<p>Dynamic wordlist discovery and multi-language UI support</p>
|
|
</div>
|
|
<div class="feature-item">
|
|
<h4>📊 Entropy Analysis</h4>
|
|
<p>Real-time password strength calculation and security metrics</p>
|
|
</div>
|
|
<div class="feature-item">
|
|
<h4>🔧 Configurable</h4>
|
|
<p>Extensive customization options for all password types</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="downloads-section">
|
|
<h2>Download Configuration Files</h2>
|
|
<p>Get the complete API specification in various formats for integration with your tools and workflows.</p>
|
|
|
|
<div class="downloads-grid">
|
|
<div class="download-card">
|
|
<h4><span class="icon">📄</span> OpenAPI JSON</h4>
|
|
<p>Complete OpenAPI 3.0 specification in JSON format. Perfect for code generation, API testing, and integration with development tools.</p>
|
|
<a href="#" class="download-btn" id="download-json">Download JSON</a>
|
|
</div>
|
|
|
|
<div class="download-card">
|
|
<h4><span class="icon">📋</span> OpenAPI YAML</h4>
|
|
<p>Human-readable YAML format specification. Ideal for documentation, version control, and collaborative API development.</p>
|
|
<a href="#" class="download-btn" id="download-yaml">Download YAML</a>
|
|
</div>
|
|
|
|
<div class="download-card">
|
|
<h4><span class="icon">🚀</span> Postman Collection</h4>
|
|
<p>Ready-to-use Postman collection with all endpoints, examples, and environment variables for immediate API testing.</p>
|
|
<a href="#" class="download-btn" id="download-postman">Download Collection</a>
|
|
</div>
|
|
|
|
<div class="download-card">
|
|
<h4><span class="icon">⚡</span> cURL Examples</h4>
|
|
<p>Complete set of cURL commands with examples for all endpoints. Perfect for command-line testing and scripting.</p>
|
|
<a href="#" class="download-btn" id="download-curl">Download Examples</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="swagger-container">
|
|
<div class="swagger-header">
|
|
<h3>Interactive API Explorer</h3>
|
|
</div>
|
|
<div class="swagger-content">
|
|
<div id="swagger-ui"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="features-section">
|
|
<h2>Quick Start</h2>
|
|
<p>Get started with the Password Generator API in minutes. Here are some common examples:</p>
|
|
|
|
<h3>Generate XKCD Passphrase</h3>
|
|
<button class="copy-btn" onclick="copyToClipboard('curl-xkcd')">Copy</button>
|
|
<div class="code-example" id="curl-xkcd">curl -X POST "http://localhost:8080/api/v1/passwords/generate" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"type": "xkcdpass",
|
|
"count": 3,
|
|
"options": {
|
|
"words": 4,
|
|
"wordlist": "en",
|
|
"separator": "-",
|
|
"add_number": true,
|
|
"number_position": "random"
|
|
}
|
|
}'</div>
|
|
|
|
<h3>Check Available Wordlists</h3>
|
|
<button class="copy-btn" onclick="copyToClipboard('curl-wordlists')">Copy</button>
|
|
<div class="code-example" id="curl-wordlists">curl -X GET "http://localhost:8080/api/v1/passwords/wordlists"</div>
|
|
|
|
<h3>Generate High-Entropy Password</h3>
|
|
<button class="copy-btn" onclick="copyToClipboard('curl-entropy')">Copy</button>
|
|
<div class="code-example" id="curl-entropy">curl -X POST "http://localhost:8080/api/v1/passwords/generate" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"type": "high-entropy",
|
|
"count": 1,
|
|
"options": {
|
|
"length": 20,
|
|
"include_symbols": true
|
|
}
|
|
}'</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="footer">
|
|
<p>
|
|
Password Generator API v2.0.0 •
|
|
<a href="/">Main Application</a> •
|
|
<a href="#swagger-ui">Interactive Docs</a>
|
|
</p>
|
|
</footer>
|
|
|
|
<script src="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui-bundle.js"></script>
|
|
<script src="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui-standalone-preset.js"></script>
|
|
<script>
|
|
// OpenAPI Specification (embedded)
|
|
const spec = {
|
|
"openapi": "3.0.3",
|
|
"info": {
|
|
"title": "Password Generator API",
|
|
"description": "Secure password generation with multiple algorithms and customizable options. Generate high-entropy passwords, XKCD-style passphrases, Diceware passwords, and more with comprehensive internationalization support.",
|
|
"version": "2.0.0",
|
|
"contact": {
|
|
"name": "Password Generator API",
|
|
"url": "http://localhost:8080"
|
|
},
|
|
"license": {
|
|
"name": "MIT",
|
|
"url": "https://opensource.org/licenses/MIT"
|
|
}
|
|
},
|
|
"servers": [
|
|
{
|
|
"url": "http://localhost:8080/api/v1",
|
|
"description": "Development server"
|
|
}
|
|
],
|
|
"paths": {
|
|
"/passwords": {
|
|
"get": {
|
|
"summary": "Get available password types",
|
|
"description": "Returns all available password generation types with their descriptions and configuration options.",
|
|
"operationId": "getPasswordTypes",
|
|
"tags": ["Password Generation"],
|
|
"responses": {
|
|
"200": {
|
|
"description": "List of available password generation types",
|
|
"content": {
|
|
"application/json": {
|
|
"schema": {
|
|
"$ref": "#/components/schemas/PasswordTypesResponse"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"/passwords/generate": {
|
|
"post": {
|
|
"summary": "Generate passwords",
|
|
"description": "Generate one or more passwords using the specified type and custom options.",
|
|
"operationId": "generatePasswords",
|
|
"tags": ["Password Generation"],
|
|
"requestBody": {
|
|
"required": true,
|
|
"content": {
|
|
"application/json": {
|
|
"schema": {
|
|
"$ref": "#/components/schemas/GeneratePasswordRequest"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"responses": {
|
|
"200": {
|
|
"description": "Successfully generated passwords",
|
|
"content": {
|
|
"application/json": {
|
|
"schema": {
|
|
"$ref": "#/components/schemas/GeneratePasswordResponse"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"400": {
|
|
"description": "Invalid request parameters",
|
|
"content": {
|
|
"application/json": {
|
|
"schema": {
|
|
"$ref": "#/components/schemas/ErrorResponse"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"/passwords/wordlists": {
|
|
"get": {
|
|
"summary": "Get available wordlists",
|
|
"description": "Returns all available wordlists for XKCD password generation with availability status. Used by frontend to dynamically populate language options.",
|
|
"operationId": "getAvailableWordlists",
|
|
"tags": ["Wordlists"],
|
|
"responses": {
|
|
"200": {
|
|
"description": "List of available wordlists",
|
|
"content": {
|
|
"application/json": {
|
|
"schema": {
|
|
"$ref": "#/components/schemas/WordlistsResponse"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"/locales/{lang}": {
|
|
"get": {
|
|
"summary": "Get localization strings",
|
|
"description": "Returns translation strings for the specified language code.",
|
|
"operationId": "getLocalization",
|
|
"tags": ["Internationalization"],
|
|
"parameters": [
|
|
{
|
|
"name": "lang",
|
|
"in": "path",
|
|
"required": true,
|
|
"description": "Language code (2-3 letters)",
|
|
"schema": {
|
|
"type": "string",
|
|
"pattern": "^[a-z]{2,3}(_[A-Z]{2})?$",
|
|
"enum": ["en", "de", "de_CH", "fr", "it", "es", "pt", "ja", "zh"]
|
|
}
|
|
}
|
|
],
|
|
"responses": {
|
|
"200": {
|
|
"description": "Localization strings for the specified language",
|
|
"content": {
|
|
"application/json": {
|
|
"schema": {
|
|
"$ref": "#/components/schemas/LocalizationResponse"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"/health": {
|
|
"get": {
|
|
"summary": "Health check",
|
|
"description": "Returns the current health status of the API service.",
|
|
"operationId": "healthCheck",
|
|
"tags": ["System"],
|
|
"responses": {
|
|
"200": {
|
|
"description": "API is healthy",
|
|
"content": {
|
|
"application/json": {
|
|
"schema": {
|
|
"$ref": "#/components/schemas/HealthResponse"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"components": {
|
|
"schemas": {
|
|
"PasswordTypesResponse": {
|
|
"type": "object",
|
|
"properties": {
|
|
"success": { "type": "boolean" },
|
|
"data": {
|
|
"type": "object",
|
|
"properties": {
|
|
"types": {
|
|
"type": "object",
|
|
"additionalProperties": {
|
|
"$ref": "#/components/schemas/PasswordType"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"message": { "type": "string" },
|
|
"timestamp": { "type": "string", "format": "date-time" }
|
|
}
|
|
},
|
|
"PasswordType": {
|
|
"type": "object",
|
|
"properties": {
|
|
"name": { "type": "string" },
|
|
"description": { "type": "string" },
|
|
"options": {
|
|
"type": "object",
|
|
"additionalProperties": true
|
|
}
|
|
}
|
|
},
|
|
"GeneratePasswordRequest": {
|
|
"type": "object",
|
|
"required": ["type"],
|
|
"properties": {
|
|
"type": {
|
|
"type": "string",
|
|
"enum": ["high-entropy", "xkcdpass", "diceware", "pwgen", "passkey"]
|
|
},
|
|
"count": {
|
|
"type": "integer",
|
|
"minimum": 1,
|
|
"maximum": 50,
|
|
"default": 1
|
|
},
|
|
"options": {
|
|
"type": "object",
|
|
"additionalProperties": true
|
|
}
|
|
}
|
|
},
|
|
"GeneratePasswordResponse": {
|
|
"type": "object",
|
|
"properties": {
|
|
"success": { "type": "boolean" },
|
|
"data": {
|
|
"type": "object",
|
|
"properties": {
|
|
"passwords": {
|
|
"type": "array",
|
|
"items": { "type": "string" }
|
|
},
|
|
"entropy_bits": { "type": "number" },
|
|
"generator_info": { "type": "string" },
|
|
"options_used": {
|
|
"type": "object",
|
|
"additionalProperties": true
|
|
}
|
|
}
|
|
},
|
|
"message": { "type": "string" },
|
|
"timestamp": { "type": "string", "format": "date-time" }
|
|
}
|
|
},
|
|
"WordlistsResponse": {
|
|
"type": "object",
|
|
"properties": {
|
|
"success": { "type": "boolean" },
|
|
"data": {
|
|
"type": "object",
|
|
"properties": {
|
|
"wordlists": {
|
|
"type": "object",
|
|
"additionalProperties": {
|
|
"$ref": "#/components/schemas/Wordlist"
|
|
}
|
|
},
|
|
"count": { "type": "integer" }
|
|
}
|
|
},
|
|
"message": { "type": "string" },
|
|
"timestamp": { "type": "string", "format": "date-time" }
|
|
}
|
|
},
|
|
"Wordlist": {
|
|
"type": "object",
|
|
"properties": {
|
|
"name": { "type": "string" },
|
|
"description": { "type": "string" },
|
|
"file": { "type": "string" },
|
|
"available": { "type": "boolean" },
|
|
"fallback": { "type": "boolean" }
|
|
}
|
|
},
|
|
"LocalizationResponse": {
|
|
"type": "object",
|
|
"additionalProperties": { "type": "string" }
|
|
},
|
|
"HealthResponse": {
|
|
"type": "object",
|
|
"properties": {
|
|
"status": {
|
|
"type": "string",
|
|
"enum": ["healthy", "degraded", "unhealthy"]
|
|
},
|
|
"version": { "type": "string" },
|
|
"timestamp": { "type": "string", "format": "date-time" }
|
|
}
|
|
},
|
|
"ErrorResponse": {
|
|
"type": "object",
|
|
"properties": {
|
|
"success": { "type": "boolean", "example": false },
|
|
"error": {
|
|
"type": "object",
|
|
"properties": {
|
|
"message": { "type": "string" },
|
|
"code": { "type": "string" },
|
|
"status": { "type": "integer" }
|
|
}
|
|
},
|
|
"timestamp": { "type": "string", "format": "date-time" }
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"tags": [
|
|
{ "name": "Password Generation", "description": "Core password generation endpoints" },
|
|
{ "name": "Wordlists", "description": "Wordlist management for XKCD passwords" },
|
|
{ "name": "Internationalization", "description": "Localization and language support" },
|
|
{ "name": "System", "description": "System health and monitoring" }
|
|
]
|
|
};
|
|
|
|
// Initialize Swagger UI
|
|
window.onload = function() {
|
|
SwaggerUIBundle({
|
|
url: '',
|
|
spec: spec,
|
|
dom_id: '#swagger-ui',
|
|
deepLinking: true,
|
|
presets: [
|
|
SwaggerUIBundle.presets.apis,
|
|
SwaggerUIStandalonePreset
|
|
],
|
|
plugins: [
|
|
SwaggerUIBundle.plugins.DownloadUrl
|
|
],
|
|
layout: "StandaloneLayout",
|
|
tryItOutEnabled: true,
|
|
requestInterceptor: (request) => {
|
|
// Add any custom headers or modifications
|
|
return request;
|
|
},
|
|
responseInterceptor: (response) => {
|
|
// Handle responses
|
|
return response;
|
|
}
|
|
});
|
|
};
|
|
|
|
// Download functions
|
|
function downloadFile(content, filename, contentType) {
|
|
const blob = new Blob([content], { type: contentType });
|
|
const url = URL.createObjectURL(blob);
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = filename;
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
URL.revokeObjectURL(url);
|
|
|
|
showNotification(`Downloaded ${filename}`);
|
|
}
|
|
|
|
function showNotification(message) {
|
|
const notification = document.createElement('div');
|
|
notification.className = 'notification';
|
|
notification.textContent = message;
|
|
document.body.appendChild(notification);
|
|
|
|
setTimeout(() => notification.classList.add('show'), 10);
|
|
setTimeout(() => {
|
|
notification.classList.remove('show');
|
|
setTimeout(() => notification.remove(), 300);
|
|
}, 3000);
|
|
}
|
|
|
|
// Download event handlers
|
|
document.getElementById('download-json').addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
downloadFile(JSON.stringify(spec, null, 2), 'password-generator-api.json', 'application/json');
|
|
});
|
|
|
|
document.getElementById('download-yaml').addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
// Convert JSON to YAML (simplified)
|
|
const yaml = jsonToYaml(spec);
|
|
downloadFile(yaml, 'password-generator-api.yaml', 'text/yaml');
|
|
});
|
|
|
|
document.getElementById('download-postman').addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const postmanCollection = generatePostmanCollection(spec);
|
|
downloadFile(JSON.stringify(postmanCollection, null, 2), 'password-generator-api.postman_collection.json', 'application/json');
|
|
});
|
|
|
|
document.getElementById('download-curl').addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const curlExamples = generateCurlExamples(spec);
|
|
downloadFile(curlExamples, 'password-generator-api-examples.sh', 'text/plain');
|
|
});
|
|
|
|
// Copy to clipboard function
|
|
function copyToClipboard(elementId) {
|
|
const element = document.getElementById(elementId);
|
|
const text = element.textContent;
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
showNotification('Copied to clipboard!');
|
|
});
|
|
}
|
|
|
|
// Utility functions for file generation
|
|
function jsonToYaml(obj, indent = 0) {
|
|
let yaml = '';
|
|
const spaces = ' '.repeat(indent);
|
|
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
if (value === null) {
|
|
yaml += `${spaces}${key}: null\n`;
|
|
} else if (typeof value === 'object' && !Array.isArray(value)) {
|
|
yaml += `${spaces}${key}:\n`;
|
|
yaml += jsonToYaml(value, indent + 1);
|
|
} else if (Array.isArray(value)) {
|
|
yaml += `${spaces}${key}:\n`;
|
|
value.forEach(item => {
|
|
if (typeof item === 'object') {
|
|
yaml += `${spaces} -\n`;
|
|
yaml += jsonToYaml(item, indent + 2);
|
|
} else {
|
|
yaml += `${spaces} - ${item}\n`;
|
|
}
|
|
});
|
|
} else {
|
|
yaml += `${spaces}${key}: ${typeof value === 'string' ? `"${value}"` : value}\n`;
|
|
}
|
|
}
|
|
return yaml;
|
|
}
|
|
|
|
function generatePostmanCollection(spec) {
|
|
return {
|
|
info: {
|
|
name: spec.info.title,
|
|
description: spec.info.description,
|
|
version: spec.info.version,
|
|
schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
|
},
|
|
variable: [
|
|
{
|
|
key: "baseUrl",
|
|
value: spec.servers[0].url,
|
|
type: "string"
|
|
}
|
|
],
|
|
item: Object.entries(spec.paths).map(([path, methods]) => {
|
|
return Object.entries(methods).map(([method, operation]) => ({
|
|
name: operation.summary,
|
|
request: {
|
|
method: method.toUpperCase(),
|
|
header: method === 'post' ? [
|
|
{
|
|
key: "Content-Type",
|
|
value: "application/json"
|
|
}
|
|
] : [],
|
|
url: {
|
|
raw: `{{baseUrl}}${path}`,
|
|
host: ["{{baseUrl}}"],
|
|
path: path.split('/').filter(p => p)
|
|
},
|
|
body: method === 'post' ? {
|
|
mode: "raw",
|
|
raw: JSON.stringify({
|
|
type: "xkcdpass",
|
|
count: 1,
|
|
options: {
|
|
words: 4,
|
|
language: "en"
|
|
}
|
|
}, null, 2)
|
|
} : undefined
|
|
}
|
|
}));
|
|
}).flat()
|
|
};
|
|
}
|
|
|
|
function generateCurlExamples(spec) {
|
|
const baseUrl = spec.servers[0].url;
|
|
let examples = `#!/bin/bash
|
|
# Password Generator API - cURL Examples
|
|
# Base URL: ${baseUrl}
|
|
|
|
echo "Password Generator API Examples"
|
|
echo "=============================="
|
|
|
|
`;
|
|
|
|
Object.entries(spec.paths).forEach(([path, methods]) => {
|
|
Object.entries(methods).forEach(([method, operation]) => {
|
|
examples += `# ${operation.summary}\n`;
|
|
examples += `echo "\\n${operation.summary}:"\n`;
|
|
|
|
if (method === 'get') {
|
|
examples += `curl -X GET "${baseUrl}${path}"\n\n`;
|
|
} else if (method === 'post') {
|
|
examples += `curl -X POST "${baseUrl}${path}" \\\n`;
|
|
examples += ` -H "Content-Type: application/json" \\\n`;
|
|
examples += ` -d '{\n`;
|
|
examples += ` "type": "xkcdpass",\n`;
|
|
examples += ` "count": 1,\n`;
|
|
examples += ` "options": {\n`;
|
|
examples += ` "words": 4,\n`;
|
|
examples += ` "wordlist": "en",\n`;
|
|
examples += ` "add_number": true\n`;
|
|
examples += ` }\n`;
|
|
examples += ` }'\n\n`;
|
|
}
|
|
});
|
|
});
|
|
|
|
return examples;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |