added swagger
This commit is contained in:
158
doc/api.md
158
doc/api.md
@@ -1,158 +0,0 @@
|
||||
|
||||
# 📄 API Documentation – **Stupid APIs**
|
||||
|
||||
## Base URL
|
||||
|
||||
```
|
||||
http://localhost:3000/api
|
||||
```
|
||||
|
||||
**Default Headers:**
|
||||
|
||||
```
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## POST `/sort`
|
||||
|
||||
Sorts an array (numeric or alphabetical) and returns the sorted array.
|
||||
|
||||
### Request
|
||||
|
||||
**URL:**
|
||||
|
||||
```
|
||||
POST /sort
|
||||
```
|
||||
|
||||
|
||||
**Body Example:**
|
||||
|
||||
```json
|
||||
{
|
||||
"input": [3, 1, 4, 1, 5, 9]
|
||||
}
|
||||
```
|
||||
|
||||
### Successful Response
|
||||
|
||||
```json
|
||||
{
|
||||
"sortedArray": [1, 1, 3, 4, 5, 9]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## POST `/isOdd`
|
||||
|
||||
Checks if a given number is odd.
|
||||
|
||||
### Request
|
||||
|
||||
**URL:**
|
||||
|
||||
```
|
||||
POST /isOdd
|
||||
```
|
||||
|
||||
**Body Example:**
|
||||
|
||||
```json
|
||||
{
|
||||
"input": 7
|
||||
}
|
||||
```
|
||||
|
||||
### Successful Response
|
||||
|
||||
```json
|
||||
{
|
||||
"ret": true
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## POST `/isEven`
|
||||
|
||||
Checks if a given number is even.
|
||||
|
||||
### Request
|
||||
|
||||
**URL:**
|
||||
|
||||
```
|
||||
POST /isEven
|
||||
```
|
||||
|
||||
**Body Example:**
|
||||
|
||||
```json
|
||||
{
|
||||
"input": 4
|
||||
}
|
||||
```
|
||||
|
||||
### Successful Response
|
||||
|
||||
```json
|
||||
{
|
||||
"ret": true
|
||||
}
|
||||
```
|
||||
|
||||
## POST `/toString`
|
||||
|
||||
calls .toString()
|
||||
|
||||
### Request
|
||||
|
||||
**URL:**
|
||||
|
||||
```
|
||||
POST /toString
|
||||
```
|
||||
|
||||
**Body Example:**
|
||||
|
||||
```json
|
||||
{
|
||||
"input": 7
|
||||
}
|
||||
```
|
||||
|
||||
### Successful Response
|
||||
|
||||
```json
|
||||
{
|
||||
"ret": "7"
|
||||
}
|
||||
```
|
||||
|
||||
## 📌 Example Usage with `curl`
|
||||
|
||||
### Sort an array (Linux/macOS)
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/sort \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"array":[3,1,4,1,5,9]}'
|
||||
```
|
||||
|
||||
### Check if odd
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/is-odd \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"number":7}'
|
||||
```
|
||||
|
||||
### Check if even
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/is-even \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"number":4}'
|
||||
```
|
||||
1258
package-lock.json
generated
1258
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -7,11 +7,11 @@
|
||||
"start": "node src/server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"body-parser": "^1.20.2",
|
||||
"express": "^4.18.2",
|
||||
"is-even": "^1.0.0",
|
||||
"is-odd": "^3.0.1",
|
||||
"showdown": "^2.1.0",
|
||||
"fs": "^0.0.1-security"
|
||||
"swagger-jsdoc": "^6.2.8",
|
||||
"swagger-ui-express": "^5.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
src/routes/docs/openapi.json
Normal file
244
src/routes/docs/openapi.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
/* markdown-dark.css */
|
||||
/* Basis: neutraler Dark-Mode mit guter Lesbarkeit und sauberem Tabellenlayout */
|
||||
:root {
|
||||
--bg: #0d1117;
|
||||
--bg-muted: #161b22;
|
||||
--text: #c9d1d9;
|
||||
--text-muted: #8b949e;
|
||||
--border: #30363d;
|
||||
--link: #58a6ff;
|
||||
--code-bg: #161b22;
|
||||
--code-text: #f0f6fc;
|
||||
--kbd-bg: #0b1020;
|
||||
--kbd-border: #30363d;
|
||||
--accent: #1f6feb;
|
||||
}
|
||||
|
||||
html, body {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.markdown-body {
|
||||
box-sizing: border-box;
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
line-height: 1.65;
|
||||
font: 16px/1.65 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Apple Color Emoji","Segoe UI Emoji";
|
||||
}
|
||||
|
||||
/* Überschriften */
|
||||
.markdown-body h1,
|
||||
.markdown-body h2,
|
||||
.markdown-body h3,
|
||||
.markdown-body h4,
|
||||
.markdown-body h5,
|
||||
.markdown-body h6 {
|
||||
color: var(--text);
|
||||
margin: 1.6em 0 .6em;
|
||||
font-weight: 700;
|
||||
line-height: 1.25;
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding-bottom: .3em;
|
||||
}
|
||||
.markdown-body h1 { font-size: 2rem; }
|
||||
.markdown-body h2 { font-size: 1.6rem; }
|
||||
.markdown-body h3 { font-size: 1.35rem; border-bottom: none; }
|
||||
.markdown-body h4 { font-size: 1.15rem; border-bottom: none; }
|
||||
.markdown-body h5 { font-size: 1rem; border-bottom: none; }
|
||||
.markdown-body h6 { font-size: .95rem; color: var(--text-muted); border-bottom: none; }
|
||||
|
||||
/* Text & Links */
|
||||
.markdown-body p, .markdown-body ul, .markdown-body ol, .markdown-body blockquote, .markdown-body pre, .markdown-body table {
|
||||
margin: 1em 0;
|
||||
}
|
||||
.markdown-body a {
|
||||
color: var(--link);
|
||||
text-decoration: none;
|
||||
}
|
||||
.markdown-body a:hover, .markdown-body a:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Listen */
|
||||
.markdown-body ul, .markdown-body ol {
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
.markdown-body li + li {
|
||||
margin-top: .25em;
|
||||
}
|
||||
|
||||
/* Code */
|
||||
.markdown-body code,
|
||||
.markdown-body tt {
|
||||
background: var(--code-bg);
|
||||
color: var(--code-text);
|
||||
padding: .15em .35em;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--border);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
||||
font-size: .95em;
|
||||
}
|
||||
.markdown-body pre {
|
||||
background: var(--code-bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 12px 14px;
|
||||
overflow: auto;
|
||||
}
|
||||
.markdown-body pre code {
|
||||
background: transparent;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
/* Blockquote */
|
||||
.markdown-body blockquote {
|
||||
border-left: 4px solid var(--border);
|
||||
padding: .5em 1em;
|
||||
margin-left: 0;
|
||||
color: var(--text-muted);
|
||||
background: rgba(22,27,34,.35);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
/* Tabellen – wichtig für sauberes Layout */
|
||||
.markdown-body table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
overflow: auto;
|
||||
display: block;
|
||||
}
|
||||
.markdown-body thead {
|
||||
background: var(--bg-muted);
|
||||
}
|
||||
.markdown-body th, .markdown-body td {
|
||||
border: 1px solid var(--border);
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
.markdown-body th {
|
||||
font-weight: 600;
|
||||
}
|
||||
.markdown-body tr:nth-child(even) td {
|
||||
background: rgba(22,27,34,.5);
|
||||
}
|
||||
|
||||
/* HR */
|
||||
.markdown-body hr {
|
||||
height: 1px;
|
||||
border: 0;
|
||||
background: var(--border);
|
||||
margin: 2em 0;
|
||||
}
|
||||
|
||||
/* Bilder */
|
||||
.markdown-body img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
/* Details/Summary */
|
||||
.markdown-body details {
|
||||
background: var(--bg-muted);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: .6em .9em;
|
||||
}
|
||||
.markdown-body summary {
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Markierung, KBD */
|
||||
.markdown-body mark {
|
||||
background: #99700066;
|
||||
color: var(--text);
|
||||
padding: 0 .2em;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.markdown-body kbd {
|
||||
background: var(--kbd-bg);
|
||||
border: 1px solid var(--kbd-border);
|
||||
border-bottom-width: 2px;
|
||||
border-radius: 6px;
|
||||
padding: .1em .4em;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
font-size: .85em;
|
||||
}
|
||||
|
||||
/* Zitate/Callouts (Admonitions via blockquote) */
|
||||
.markdown-body blockquote > :first-child { margin-top: 0; }
|
||||
.markdown-body blockquote > :last-child { margin-bottom: 0; }
|
||||
|
||||
/* Inline-Abstände */
|
||||
.markdown-body strong { color: var(--text); }
|
||||
.markdown-body em { color: var(--text); }
|
||||
|
||||
/* Code-Block Scrollbar etwas dezenter */
|
||||
.markdown-body pre::-webkit-scrollbar,
|
||||
.markdown-body table::-webkit-scrollbar {
|
||||
height: 10px;
|
||||
}
|
||||
.markdown-body pre::-webkit-scrollbar-thumb,
|
||||
.markdown-body table::-webkit-scrollbar-thumb {
|
||||
background: var(--border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
Reference in New Issue
Block a user