diff --git a/app.py b/app.py index eb3c0d6..8fc91fb 100644 --- a/app.py +++ b/app.py @@ -302,6 +302,10 @@ def api_monitor(): "pageviews_last_7_days": pageviews }) +@app.route('/api-docs') +def api_docs(): + return render_template('swagger.html') + if __name__ == '__main__': app.run(debug=True, host="0.0.0.0") \ No newline at end of file diff --git a/static/swagger.json b/static/swagger.json new file mode 100644 index 0000000..4c1ab0a --- /dev/null +++ b/static/swagger.json @@ -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" } + } + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index d4ab0c9..2bada7e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -240,6 +240,7 @@
+ + + +diff --git a/templates/swagger.html b/templates/swagger.html new file mode 100644 index 0000000..96763ba --- /dev/null +++ b/templates/swagger.html @@ -0,0 +1,28 @@ + + +
+ +
+ + + +
+