1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-09 20:22:47 +01: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", "openapi": "3.1.0",
"info": { "info": {
"title": "Spacebar Server", "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": { "license": {
"name": "AGPLV3", "name": "AGPLV3",
"url": "https://www.gnu.org/licenses/agpl-3.0.en.html" "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 openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json"); const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" })); const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" }));
// const specification = JSON.parse(
// fs.readFileSync(openapiPath, { encoding: "utf8" }),
// );
let specification = { let specification = {
openapi: "3.1.0", openapi: "3.1.0",
info: { info: {
title: "Spacebar Server", title: "Spacebar Server",
description: 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: { license: {
name: "AGPLV3", name: "AGPLV3",
url: "https://www.gnu.org/licenses/agpl-3.0.en.html", url: "https://www.gnu.org/licenses/agpl-3.0.en.html",
@ -68,8 +66,9 @@ let specification = {
paths: {}, paths: {},
}; };
const schemaRegEx = new RegExp(/^[\w.]+$/);
function combineSchemas(schemas) { function combineSchemas(schemas) {
var definitions = {}; let definitions = {};
for (const name in schemas) { for (const name in schemas) {
definitions = { definitions = {
@ -84,9 +83,8 @@ function combineSchemas(schemas) {
} }
for (const key in definitions) { for (const key in definitions) {
const reg = new RegExp(/^[a-zA-Z0-9.\-_]+$/, "gm"); if (!schemaRegEx.test(key)) {
if (!reg.test(key)) { console.error(`Invalid schema name: ${key}`);
console.error(`Invalid schema name: ${key} (${reg.test(key)})`);
continue; continue;
} }
specification.components = specification.components || {}; specification.components = specification.components || {};
@ -157,32 +155,30 @@ function apiRoutes() {
}, },
}, },
}, },
}.merge(obj.requestBody); };
} }
if (route.responses) { if (route.responses) {
for (const [k, v] of Object.entries(route.responses)) { obj.responses = {};
let schema = {
$ref: `#/components/schemas/${v.body}`,
};
obj.responses = { for (const [k, v] of Object.entries(route.responses)) {
[k]: { if (v.body)
...(v.body obj.responses[k] = {
? { description: obj?.responses?.[k]?.description || "",
description:
obj?.responses?.[k]?.description || "",
content: { content: {
"application/json": { "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 { } else {
obj.responses = { obj.responses = {