From ebdc6f943332bfe6541bbb009865f4dc5facb06a Mon Sep 17 00:00:00 2001 From: CyferShepard Date: Sat, 4 Jan 2025 04:13:33 +0200 Subject: [PATCH] updated swagger doc added hacky code to add param enums to sort field, to fix later --- backend/swagautogen.js | 41 +++++++++++++++++++++- backend/swagger.json | 78 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/backend/swagautogen.js b/backend/swagautogen.js index 3520a8e..76b6ec4 100644 --- a/backend/swagautogen.js +++ b/backend/swagautogen.js @@ -1,4 +1,5 @@ const swaggerAutogen = require("swagger-autogen")(); +const fs = require("fs"); const outputFile = "./swagger.json"; const endpointsFiles = ["./server.js"]; @@ -55,4 +56,42 @@ const config = { module.exports = config; -swaggerAutogen(outputFile, endpointsFiles, config); +const modifySwaggerFile = (filePath) => { + const swaggerData = JSON.parse(fs.readFileSync(filePath, "utf8")); + + const endpointsToModify = ["/api/getHistory", "/api/getLibraryHistory", "/api/getUserHistory", "/api/getItemHistory"]; // Add more endpoints as needed + + endpointsToModify.forEach((endpoint) => { + if (swaggerData.paths[endpoint]) { + const methods = Object.keys(swaggerData.paths[endpoint]); + methods.forEach((method) => { + const parameters = swaggerData.paths[endpoint][method].parameters; + if (parameters) { + parameters.forEach((param) => { + if (param.name === "sort") { + param.enum = [ + "UserName", + "RemoteEndPoint", + "NowPlayingItemName", + "Client", + "DeviceName", + "ActivityDateInserted", + "PlaybackDuration", + ]; + + if (endpoint.includes("getHistory") || endpoint.includes("getLibraryHistory")) { + param.enum.push("TotalPlays"); + } + } + }); + } + }); + } + }); + + fs.writeFileSync(filePath, JSON.stringify(swaggerData, null, 2)); +}; + +swaggerAutogen(outputFile, endpointsFiles, config).then(() => { + modifySwaggerFile(outputFile); +}); diff --git a/backend/swagger.json b/backend/swagger.json index c036d86..d994fa4 100644 --- a/backend/swagger.json +++ b/backend/swagger.json @@ -2022,6 +2022,26 @@ "name": "search", "in": "query", "type": "string" + }, + { + "name": "sort", + "in": "query", + "type": "string", + "enum": [ + "UserName", + "RemoteEndPoint", + "NowPlayingItemName", + "Client", + "DeviceName", + "ActivityDateInserted", + "PlaybackDuration", + "TotalPlays" + ] + }, + { + "name": "desc", + "in": "query", + "type": "string" } ], "responses": { @@ -2077,6 +2097,26 @@ "in": "query", "type": "string" }, + { + "name": "sort", + "in": "query", + "type": "string", + "enum": [ + "UserName", + "RemoteEndPoint", + "NowPlayingItemName", + "Client", + "DeviceName", + "ActivityDateInserted", + "PlaybackDuration", + "TotalPlays" + ] + }, + { + "name": "desc", + "in": "query", + "type": "string" + }, { "name": "body", "in": "body", @@ -2149,6 +2189,25 @@ "in": "query", "type": "string" }, + { + "name": "sort", + "in": "query", + "type": "string", + "enum": [ + "UserName", + "RemoteEndPoint", + "NowPlayingItemName", + "Client", + "DeviceName", + "ActivityDateInserted", + "PlaybackDuration" + ] + }, + { + "name": "desc", + "in": "query", + "type": "string" + }, { "name": "body", "in": "body", @@ -2221,6 +2280,25 @@ "in": "query", "type": "string" }, + { + "name": "sort", + "in": "query", + "type": "string", + "enum": [ + "UserName", + "RemoteEndPoint", + "NowPlayingItemName", + "Client", + "DeviceName", + "ActivityDateInserted", + "PlaybackDuration" + ] + }, + { + "name": "desc", + "in": "query", + "type": "string" + }, { "name": "body", "in": "body",