updated swagger doc

added hacky code to add param enums to sort field, to fix later
This commit is contained in:
CyferShepard
2025-01-04 04:13:33 +02:00
parent 76363ea0ba
commit ebdc6f9433
2 changed files with 118 additions and 1 deletions

View File

@@ -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);
});

View File

@@ -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",