Swagger/OpenAPI-Doku unter /api-docs, Link im Footer, keine Überschneidung mit API-Endpunkten
This commit is contained in:
4
app.py
4
app.py
@@ -302,6 +302,10 @@ def api_monitor():
|
|||||||
"pageviews_last_7_days": pageviews
|
"pageviews_last_7_days": pageviews
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@app.route('/api-docs')
|
||||||
|
def api_docs():
|
||||||
|
return render_template('swagger.html')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, host="0.0.0.0")
|
app.run(debug=True, host="0.0.0.0")
|
223
static/swagger.json
Normal file
223
static/swagger.json
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
{
|
||||||
|
"openapi": "3.0.3",
|
||||||
|
"info": {
|
||||||
|
"title": "Elpatrons Datumsrechner API",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "REST-API für Datumsberechnungen."
|
||||||
|
},
|
||||||
|
"servers": [
|
||||||
|
{ "url": "/api" }
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/tage_werktage": {
|
||||||
|
"post": {
|
||||||
|
"summary": "Berechnet die Anzahl der Tage oder Werktage zwischen zwei Daten.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"start": { "type": "string", "format": "date" },
|
||||||
|
"end": { "type": "string", "format": "date" },
|
||||||
|
"werktage": { "type": "boolean", "default": false }
|
||||||
|
},
|
||||||
|
"required": ["start", "end"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Ergebnis der Berechnung.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"result": { "type": "integer" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": { "description": "Ungültige Eingabe" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/wochentag": {
|
||||||
|
"post": {
|
||||||
|
"summary": "Gibt den Wochentag zu einem Datum zurück.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"datum": { "type": "string", "format": "date" }
|
||||||
|
},
|
||||||
|
"required": ["datum"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Wochentag als Text.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"result": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": { "description": "Ungültige Eingabe" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/kw_berechnen": {
|
||||||
|
"post": {
|
||||||
|
"summary": "Berechnet die Kalenderwoche zu einem Datum.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"datum": { "type": "string", "format": "date" }
|
||||||
|
},
|
||||||
|
"required": ["datum"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Kalenderwoche und Jahr.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"result": { "type": "string" },
|
||||||
|
"kw": { "type": "integer" },
|
||||||
|
"jahr": { "type": "integer" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": { "description": "Ungültige Eingabe" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/kw_datum": {
|
||||||
|
"post": {
|
||||||
|
"summary": "Berechnet Start- und Enddatum einer Kalenderwoche.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"jahr": { "type": "integer" },
|
||||||
|
"kw": { "type": "integer" }
|
||||||
|
},
|
||||||
|
"required": ["jahr", "kw"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Start- und Enddatum der Kalenderwoche.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"result": { "type": "string" },
|
||||||
|
"start": { "type": "string", "format": "date" },
|
||||||
|
"end": { "type": "string", "format": "date" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": { "description": "Ungültige Eingabe" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/plusminus": {
|
||||||
|
"post": {
|
||||||
|
"summary": "Berechnet ein Datum plus/minus X Tage, Wochen oder Monate.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"datum": { "type": "string", "format": "date" },
|
||||||
|
"anzahl": { "type": "integer" },
|
||||||
|
"einheit": { "type": "string", "enum": ["tage", "wochen", "monate"] },
|
||||||
|
"richtung": { "type": "string", "enum": ["add", "sub"], "default": "add" },
|
||||||
|
"werktage": { "type": "boolean", "default": false }
|
||||||
|
},
|
||||||
|
"required": ["datum", "anzahl", "einheit"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Berechnetes Datum.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"result": { "type": "string", "format": "date" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": { "description": "Ungültige Eingabe" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/monitor": {
|
||||||
|
"get": {
|
||||||
|
"summary": "Status- und Monitoring-Informationen zur App.",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Status-Objekt mit Uptime und Pageviews.",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"status": { "type": "string" },
|
||||||
|
"message": { "type": "string" },
|
||||||
|
"time": { "type": "string", "format": "date-time" },
|
||||||
|
"uptime_seconds": { "type": "integer" },
|
||||||
|
"pageviews_last_7_days": { "type": "integer" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -240,6 +240,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<footer style="text-align:center; margin-top:2em; color:#64748b; font-size:0.98em; padding-bottom:1.5em;">
|
<footer style="text-align:center; margin-top:2em; color:#64748b; font-size:0.98em; padding-bottom:1.5em;">
|
||||||
Dies ist ein werbe- und trackingfreier <a href="https://codeberg.org/elpatron/datecalc/src/branch/main/README.md" target="_blank" style="color:#2563eb; text-decoration:underline;">Open Source Datumsrechner</a><br>
|
Dies ist ein werbe- und trackingfreier <a href="https://codeberg.org/elpatron/datecalc/src/branch/main/README.md" target="_blank" style="color:#2563eb; text-decoration:underline;">Open Source Datumsrechner</a><br>
|
||||||
|
<a href="/api-docs" target="_blank" style="color:#2563eb; text-decoration:underline;">REST API Dokumentation (Swagger)</a><br>
|
||||||
© 2025 <a href="mailto:elpatron@mailbox.org?subject=Datumsrechner" style="color:#2563eb; text-decoration:underline;">M. Busche</a>
|
© 2025 <a href="mailto:elpatron@mailbox.org?subject=Datumsrechner" style="color:#2563eb; text-decoration:underline;">M. Busche</a>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
|
28
templates/swagger.html
Normal file
28
templates/swagger.html
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>API-Dokumentation – Swagger UI</title>
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist/swagger-ui.css">
|
||||||
|
<style>
|
||||||
|
body { margin: 0; background: #f8fafc; }
|
||||||
|
#swagger-ui { max-width: 900px; margin: 2em auto; background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(30,41,59,0.07); }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="swagger-ui"></div>
|
||||||
|
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>
|
||||||
|
<script>
|
||||||
|
window.onload = function() {
|
||||||
|
SwaggerUIBundle({
|
||||||
|
url: '/static/swagger.json',
|
||||||
|
dom_id: '#swagger-ui',
|
||||||
|
presets: [SwaggerUIBundle.presets.apis],
|
||||||
|
layout: "BaseLayout",
|
||||||
|
docExpansion: 'list',
|
||||||
|
defaultModelsExpandDepth: 1
|
||||||
|
});
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user