diff --git a/scripts/generate-openapi.mjs b/scripts/generate-openapi.mjs new file mode 100644 index 0000000..9a89f0a --- /dev/null +++ b/scripts/generate-openapi.mjs @@ -0,0 +1,18 @@ +import swaggerJsdoc from 'swagger-jsdoc'; +import { mkdirSync, writeFileSync } from 'node:fs'; +import { dirname } from 'node:path'; + +const spec = swaggerJsdoc({ + definition: { + openapi: '3.0.0', + info: { title: 'PsalmTafel API', version: '1.0.0' }, + }, + apis: ['./app/api/**/*.ts'], + failOnErrors: true, +}); + +const out = 'src/generated/openapi.json'; +mkdirSync(dirname(out), { recursive: true }); +writeFileSync(out, JSON.stringify(spec, null, 2)); + +console.log(`OpenAPI: ${Object.keys(spec.paths ?? {}).length} Pfade -> ${out}`); diff --git a/src/generated/openapi.json b/src/generated/openapi.json new file mode 100644 index 0000000..86a68dc --- /dev/null +++ b/src/generated/openapi.json @@ -0,0 +1,577 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "PsalmTafel API", + "version": "1.0.0" + }, + "paths": { + "/api/songs": { + "get": { + "summary": "Get all songs", + "responses": { + "200": { + "description": "List of songs" + }, + "500": { + "description": "Internal Server Error" + } + } + }, + "post": { + "summary": "Creates a new song", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "example": "Großer Gott" + } + } + } + } + } + }, + "responses": { + "201": { + "description": "Songbook successfully created", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean", + "example": true + }, + "songBook": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "example": 1 + }, + "title": { + "type": "string", + "example": "Großer Gott" + } + } + } + } + } + } + } + }, + "400": { + "description": "Bad Request (missing name)" + }, + "409": { + "description": "Conflict (title already exists)" + }, + "500": { + "description": "Internal Server Error" + } + } + } + }, + "/api/songs/{id}": { + "get": { + "summary": "Einzelnen Song abrufen", + "tags": [ + "Songs" + ], + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songs" + } + ], + "responses": { + "200": { + "description": "Song erfolgreich gefunden" + }, + "400": { + "description": "Ungültige Song-ID" + }, + "404": { + "description": "Song nicht gefunden" + }, + "500": { + "description": "Serverfehler" + } + } + }, + "patch": { + "summary": "Song aktualisieren", + "tags": [ + "Songs" + ], + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songs" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "responses": { + "200": { + "description": "Song erfolgreich aktualisiert" + }, + "400": { + "description": "Ungültige Parameter oder Daten" + }, + "404": { + "description": "Song nicht gefunden" + }, + "500": { + "description": "Serverfehler" + } + } + }, + "delete": { + "summary": "Song löschen", + "tags": [ + "Songs" + ], + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songs" + } + ], + "responses": { + "200": { + "description": "Song erfolgreich gelöscht" + }, + "400": { + "description": "Ungültige Song-ID" + }, + "404": { + "description": "Song nicht gefunden" + }, + "500": { + "description": "Serverfehler" + } + } + } + }, + "/api/songbooks": { + "get": { + "summary": "Get all songbooks", + "responses": { + "200": { + "description": "List of songbooks" + }, + "500": { + "description": "Internal Server Error" + } + } + }, + "post": { + "summary": "Creates a new songbook", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "title" + ], + "properties": { + "title": { + "type": "string", + "example": "Feiert Jesus 1" + }, + "language": { + "type": "string", + "example": "DE" + } + } + } + } + } + }, + "responses": { + "201": { + "description": "Songbook successfully created", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean", + "example": true + }, + "songBook": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "example": 1 + }, + "title": { + "type": "string", + "example": "Feiert Jesus 1" + }, + "language": { + "type": "string", + "example": "DE" + } + } + } + } + } + } + } + }, + "400": { + "description": "Bad Request (missing title)" + }, + "409": { + "description": "Conflict (title already exists)" + }, + "500": { + "description": "Internal Server Error" + } + } + } + }, + "/api/songbooks/{id}": { + "get": { + "summary": "Einzelnen Songbook abrufen", + "tags": [ + "Songbooks" + ], + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songbooks" + } + ], + "responses": { + "200": { + "description": "Songbook erfolgreich gefunden" + }, + "400": { + "description": "Ungültige Songbook-ID" + }, + "404": { + "description": "Songbook nicht gefunden" + }, + "500": { + "description": "Serverfehler" + } + } + }, + "patch": { + "summary": "Songbook aktualisieren", + "tags": [ + "Songbooks" + ], + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songbooks" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "responses": { + "200": { + "description": "Songbook erfolgreich aktualisiert" + }, + "400": { + "description": "Ungültige Parameter oder Daten" + }, + "404": { + "description": "Songbook nicht gefunden" + }, + "500": { + "description": "Serverfehler" + } + } + }, + "delete": { + "summary": "Songbook löschen", + "tags": [ + "Songbooks" + ], + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songbooks" + } + ], + "responses": { + "200": { + "description": "Songbook erfolgreich gelöscht" + }, + "400": { + "description": "Ungültige Songbook-ID" + }, + "404": { + "description": "Songbook nicht gefunden" + }, + "500": { + "description": "Serverfehler" + } + } + } + }, + "/api/songbooks/{id}/songs": { + "get": { + "summary": "Einen Song nach Nummer in einem Songbook suchen", + "tags": [ + "Songbook" + ], + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songbooks" + } + ], + "responses": { + "200": { + "description": "Songbook erfolgreich gefunden" + }, + "400": { + "description": "Ungültige Songbook-ID" + }, + "404": { + "description": "Songbook nicht gefunden" + }, + "500": { + "description": "Serverfehler" + } + } + } + }, + "/api/songbooks/{songBookId}/songs/{songId}": { + "post": { + "summary": "Song zu Liederbuch hinzufügen", + "tags": [ + "Songbook" + ], + "parameters": [ + { + "in": "path", + "name": "songBookId", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Liederbuchs" + }, + { + "in": "path", + "name": "songId", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songs" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "number" + ], + "properties": { + "number": { + "type": "string", + "example": "104a", + "description": "Die Songnummer im Liederbuch" + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Song erfolgreich zugewiesen" + }, + "400": { + "description": "Ungültige Parameter oder fehlende Songnummer" + }, + "409": { + "description": "Songnummer bereits vergeben oder Song existiert bereits im Buch" + }, + "500": { + "description": "Serverfehler" + } + } + }, + "patch": { + "summary": "Songnummer eines Songs im Liederbuch aktualisieren", + "tags": [ + "Songbook" + ], + "parameters": [ + { + "in": "path", + "name": "songBookId", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Liederbuchs" + }, + { + "in": "path", + "name": "songId", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songs" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "number" + ], + "properties": { + "number": { + "type": "string", + "example": "105", + "description": "Die neue Songnummer im Liederbuch" + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Songnummer erfolgreich aktualisiert" + }, + "400": { + "description": "Ungültige Parameter oder fehlende Daten" + }, + "404": { + "description": "Zuweisung nicht gefunden" + }, + "409": { + "description": "Neue Songnummer bereits vergeben" + }, + "500": { + "description": "Serverfehler" + } + } + }, + "delete": { + "summary": "Song aus Liederbuch entfernen", + "tags": [ + "Songbook" + ], + "parameters": [ + { + "in": "path", + "name": "songBookId", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Liederbuchs" + }, + { + "in": "path", + "name": "songId", + "required": true, + "schema": { + "type": "integer" + }, + "description": "Die ID des Songs" + } + ], + "responses": { + "200": { + "description": "Song erfolgreich aus dem Liederbuch entfernt" + }, + "400": { + "description": "Ungültige Parameter" + }, + "404": { + "description": "Zuweisung nicht gefunden" + }, + "500": { + "description": "Serverfehler" + } + } + } + } + }, + "components": {}, + "tags": [] +} \ No newline at end of file