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

@ -1,17 +1,17 @@
/* /*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
@ -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: content: {
obj?.responses?.[k]?.description || "", "application/json": {
content: { schema: {
"application/json": { $ref: `#/components/schemas/${v.body}`,
schema: schema, },
}, },
}, },
} };
: { else
description: "No description available", obj.responses[k] = {
}), description:
}, obj?.responses?.[k]?.description ||
}.merge(obj.responses); "No description available",
};
} }
} else { } else {
obj.responses = { obj.responses = {