1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-19 17:21:35 +02:00

Slight code cleanup & update project desc

This commit is contained in:
TomatoCake 2024-08-21 19:08:25 +02:00
parent 339b947a8d
commit 0d6cb63096
2 changed files with 30 additions and 34 deletions

View File

@ -2,7 +2,7 @@
"openapi": "3.1.0",
"info": {
"title": "Spacebar Server",
"description": "Spacebar is a free open source selfhostable discord compatible chat, voice and video platform",
"description": "Spacebar is a Discord.com server implementation and extension, with the goal of complete feature parity with Discord.com, all while adding some additional goodies, security, privacy, and configuration options.",
"license": {
"name": "AGPLV3",
"url": "https://www.gnu.org/licenses/agpl-3.0.en.html"

View File

@ -28,15 +28,13 @@ require("missing-native-js-functions");
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" }));
// const specification = JSON.parse(
// fs.readFileSync(openapiPath, { encoding: "utf8" }),
// );
let specification = {
openapi: "3.1.0",
info: {
title: "Spacebar Server",
description:
"Spacebar is a free open source selfhostable discord compatible chat, voice and video platform",
"Spacebar is a Discord.com server implementation and extension, with the goal of complete feature parity with Discord.com, all while adding some additional goodies, security, privacy, and configuration options.",
license: {
name: "AGPLV3",
url: "https://www.gnu.org/licenses/agpl-3.0.en.html",
@ -68,8 +66,9 @@ let specification = {
paths: {},
};
const schemaRegEx = new RegExp(/^[\w.]+$/);
function combineSchemas(schemas) {
var definitions = {};
let definitions = {};
for (const name in schemas) {
definitions = {
@ -84,9 +83,8 @@ function combineSchemas(schemas) {
}
for (const key in definitions) {
const reg = new RegExp(/^[a-zA-Z0-9.\-_]+$/, "gm");
if (!reg.test(key)) {
console.error(`Invalid schema name: ${key} (${reg.test(key)})`);
if (!schemaRegEx.test(key)) {
console.error(`Invalid schema name: ${key}`);
continue;
}
specification.components = specification.components || {};
@ -157,32 +155,30 @@ function apiRoutes() {
},
},
},
}.merge(obj.requestBody);
};
}
if (route.responses) {
for (const [k, v] of Object.entries(route.responses)) {
let schema = {
$ref: `#/components/schemas/${v.body}`,
};
obj.responses = {};
obj.responses = {
[k]: {
...(v.body
? {
description:
obj?.responses?.[k]?.description || "",
for (const [k, v] of Object.entries(route.responses)) {
if (v.body)
obj.responses[k] = {
description: obj?.responses?.[k]?.description || "",
content: {
"application/json": {
schema: schema,
schema: {
$ref: `#/components/schemas/${v.body}`,
},
},
}
: {
description: "No description available",
}),
},
}.merge(obj.responses);
};
else
obj.responses[k] = {
description:
obj?.responses?.[k]?.description ||
"No description available",
};
}
} else {
obj.responses = {