added swagger

This commit is contained in:
Maximilian Baum
2026-04-02 09:36:29 +02:00
parent 8ac8643e6d
commit 88ef8136f3
6 changed files with 1509 additions and 391 deletions
+4 -36
View File
@@ -1,41 +1,9 @@
const express = require('express');
const showdown = require('showdown');
const fs = require('fs');
const path = require('path');
const converter = new showdown.Converter({
tables: true, // Tabellen-Unterstützung aktivieren
ghCompatibleHeaderId: true,
simpleLineBreaks: true,
emoji: true
});
const router = express.Router();
const swaggerUi = require('swagger-ui-express');
const openAPI = require('./openapi.json');
router.get('/', (req, res) => {
const filePath = path.join(__dirname, '../../../doc/api.md');
fs.readFile(filePath, 'utf-8', (err, data) => {
if (err) {
console.error(err);
return res.status(500).send("Fehler beim Laden der Markdown-Datei");
}
const htmlContent = converter.makeHtml(data);
res.set('Content-Type', 'text/html; charset=utf-8');
res.send(`<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title>API-Dokumentation</title>
<link rel="stylesheet" href="/css/markdown-dark.css">
</head>
<body>
<main class="markdown-body">
${htmlContent}
</main>
</body>
</html>`);
});
});
router.use('/', swaggerUi.serve);
router.get('/', swaggerUi.setup(openAPI));
module.exports = router;
+244
View File
@@ -0,0 +1,244 @@
{
"openapi": "3.0.0",
"info": {
"title": "Stupid APIs",
"version": "1.0.0",
"description": "API Documentation for Stupid APIs"
},
"servers": [
{
"url": "http://localhost:3000/api",
"description": "Local server"
}
],
"paths": {
"/sort": {
"post": {
"summary": "Sorts an array",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "array",
"items": {}
}
}
}
}
}
},
"responses": {
"200": {
"description": "Sorted array",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"sortedArray": {
"type": "array",
"items": {}
}
}
}
}
}
}
}
}
},
"/isEven": {
"post": {
"summary": "Checks if number is even",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "number"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/isEven/{number}": {
"get": {
"summary": "Checks if number is even",
"parameters": [
{
"name": "number",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/isOdd": {
"post": {
"summary": "Checks if number is odd",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "number"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/isOdd/{number}": {
"get": {
"summary": "Checks if number is odd",
"parameters": [
{
"name": "number",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/isNumber": {
"post": {
"summary": "Checks if input is a number",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/isNumber/{number}": {
"get": {
"summary": "Checks if param is a number",
"parameters": [
{
"name": "number",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/toString": {
"post": {
"summary": "Converts input to string",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/stringSplit": {
"post": {
"summary": "Splits a string",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"string": {
"type": "string"
},
"seperator": {
"type": "string"
}
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
}
}
}