feat(swagger): Add Swagger API reference, and fixes #28

Merged
Gandalf merged 28 commits from develop into main 2026-05-21 20:14:36 +01:00
4 changed files with 50 additions and 5 deletions
Showing only changes of commit 52a75fd8cb - Show all commits
+45
View File
@@ -0,0 +1,45 @@
// Swagger UI server URL auto-detection
// Automatically sets the server URL to match the current instance
(function() {
window.addEventListener('load', function() {
// Wait for Swagger UI to initialize
setTimeout(function() {
try {
// Detect current URL from browser
const protocol = window.location.protocol;
const host = window.location.host;
const detectedUrl = `${protocol}//${host}`;
// Get Swagger UI instance
const ui = window.ui;
if (!ui) {
console.warn('Swagger UI not found, cannot set server URL');
return;
}
// Get the spec servers
const spec = ui.specSelectors.specJson();
const servers = spec.getIn(['servers']);
if (!servers || servers.size === 0) {
console.warn('No servers defined in OpenAPI spec');
return;
}
// Update the first server with the detected URL
const updatedServers = servers.setIn([0, 'url'], detectedUrl);
// Apply the updated servers to the spec
const updatedSpec = spec.set('servers', updatedServers);
ui.specActions.updateSpec(updatedSpec.toJS());
// Also set the selected server in Swagger UI state
ui.specActions.setSelectedServer(updatedServers.get(0).get('url'));
console.log('Swagger UI server URL set to:', detectedUrl);
} catch (error) {
console.error('Failed to auto-detect Swagger UI server URL:', error);
}
}, 100); // Small delay to ensure Swagger UI is initialized
});
})();
+2 -1
View File
@@ -185,7 +185,8 @@ function createApp({ skipRateLimits = false } = {}) {
customSiteTitle: 'sofarr API Documentation',
customCss: '.swagger-ui .topbar { display: none }',
customJs: [
'/swagger-auth-banner.js'
'/swagger-auth-banner.js',
'/swagger-server-detection.js'
]
}));
+2 -1
View File
@@ -300,7 +300,8 @@ app.use('/api/swagger', swaggerUi.serve, swaggerUi.setup(swaggerSpec, {
customSiteTitle: 'sofarr API Documentation',
customCss: '.swagger-ui .topbar { display: none }',
customJs: [
'/swagger-auth-banner.js'
'/swagger-auth-banner.js',
'/swagger-server-detection.js'
]
}));
+1 -3
View File
@@ -25,10 +25,8 @@ info:
name: MIT
servers:
- url: http://localhost:3001
description: Local development server
- url: https://sofarr.example.com
description: Production server
description: sofarr API (auto-detected from current URL)
tags:
- name: Health