From 339b947a8d471a42686ad58b950c9eafe10463e0 Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:50:31 +0200 Subject: [PATCH 1/3] Exclude more internal schemas --- assets/openapi.json | Bin 617567 -> 608216 bytes assets/schemas.json | Bin 23504303 -> 21128458 bytes scripts/schema.js | 11 ++++++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index 68adb4556eac99d06647d081f6de81280f125da2..ea95a1bde82e97a794d2dbe98b2ec7932b641039 100644 GIT binary patch delta 152 zcmcbAL-j_#>V|BN$@j$twr907i7-#IXW`y{tBdKmXtRcRyM{R9b`5c+Pf?Tk#HF?$ zT)-qaZTf~2Ot#Yx#51c-f7iuqvVEdCvxnLAZD!0elN;h~rZ=o+W}AM%f~jS?|6j(~ z=@U#@W=-F4kjY{Cg#s4I>2fB_?9(00nPow0+ou*V12GE_vjQ<25VLQeTEKDYHvnq{ BI*R}R delta 1789 zcmeHHU2GIp6wbYOW_F<$Dx7*Gxtx_7=t!RUxg_csa5W_;LHDG`4?%sBX-OkL; zOp#3*X*I};hLmf18XwFyDzB^|u_U}uV}gl4Dd`I_CeSw$jiDG5LQM4TY=7iIpM5Zy zlexL)-1D7#zVF<-mmBWgZOEs*}S#qI7S)peF`hSg<~0JRAzs2gUk;zo$v z#BDJ0B9hT5-u2NdS1No`lFuqx<$%|uj>9ZH3ZV(o;vG5@+57TfQ$0*S zkoL^Jf%d`@;GNL9fVV?Fs0{E@uUgEK>BoU}xXwFrHPkgBk3hQ9U&$j^Yo*uLp!{%u z7Y=jt?FN~eCez_W33{G)9t}g(k9+wKPZXG1RVpDTDO>o|Ta9qskB`DLJ7xdVTR2I1 zmsC6%35$@jcVyqwAthtX>0?f}VWc!bKjU5(LLN1&9tvgGa2?$GMkzfIWtP|)w^b*} zRNG{6ZB%0kmBt;-&{g458I31ZmS*EjcT`PRsrW35W}6{YLFzY($0-Jj7bO+)KE?ms zT8tVubXybD=wqre>SCl=)?Q!3{O_V0>-Xd%gED{L-t31Y5G`1_fJ1K5)_+Z^o}=jr zrkYf<{vrR?;o(kA&`TWy7DqPw{sN4Aj$ZYwdEw9lR6_(ie5JjbfB(b-pPk13Vkwau zB%rt*j6-Hl@{{lw19}@({k_>dv%jjq&-~X_L|nG;$96HSa6>r!uGH!|$!t@!hEIj| zOW_!`A)iClByLzx)`|i=e@lV*ZRCR?ii5IY(#!;W@j4Eahy}A)LbF($hkh%E{C83% z&jkbglOKKW>7h${2rcL#ET2Kc?hI^*Jj5f-!J-aZcgU5nwB1{S3^-ANS|Ha$nhUd` z@Ov)>`N&rtMJc<30%}%zQ+A65^)cGV)suss^$J!FsnAKuK@@{kS+3#HUKyf2xOeuZ zQv0lsJdLGUpJOpP-cI%GLB8760j0I139e0|vr5cJWczIhQ8Kv2Rn*~$(NVtAw0lES zB$hUS)@@SN3#Bra$Pwy5W=5(lOp^oCGTF0ngfI2W{MWu3*CoZ%hQ1;GBF~#pF#i*( zmIOo$X1r20O7Q76zbCv_7LA|)5yuO3x~P&srF{CLe{Zf@`}vnKR_xNpOO|B@(~3UpRE7s`p?sKJ>{(@O3!)I zVm3Tn7L#M_z`^U6OCD7&d^m~AX5s!E-iG!8S`_3z%z7HRIZy?;t)$`0ax&Ql+sesq z_+<{ChWxi=7mo%?VQLu#W-p+2SSphSp+mxFOctgH^DLOhyvaZQ0@BD= Av;Y7A diff --git a/assets/schemas.json b/assets/schemas.json index a4da25385e69d5599b0b857eb65b3dec14846f59..588914aafabafd7551c41385f82a1f59d9f060d8 100644 GIT binary patch delta 3207 zcmZvedr;I>6vyZ80~Qw81?3?N=;i|qM4<4Q0|;Uo_`p{@MnNMHG{t=23pNqg#{epf zX9?v;Dn+0!ro#z!`r+VP3^OMpOKpfUh0tnjaD@8p?o8vk?tj1E=X}q(-`~0Sckead z_*lK?`fle2cLl681!_?(SLVvfhB`(I_eEExM*UN#r7ypStZ*^1m*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M&3^#rKNp1n diff --git a/scripts/schema.js b/scripts/schema.js index ff3280ac..fd5b09f5 100644 --- a/scripts/schema.js +++ b/scripts/schema.js @@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + 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 by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -41,11 +41,16 @@ const Excluded = [ "EntitySchema", "ServerResponse", "Http2ServerResponse", + "ExpressResponse", "global.Express.Response", + "global.Response", "Response", "e.Response", "request.Response", "supertest.Response", + "DiagnosticsChannel.Response", + "_Response", + "ReadableStream", // TODO: Figure out how to exclude schemas from node_modules? "SomeJSONSchema", From 0d6cb6309627cecce31ed78768c8b960260125c1 Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:08:25 +0200 Subject: [PATCH 2/3] Slight code cleanup & update project desc --- assets/openapi.json | Bin 608216 -> 608332 bytes scripts/openapi.js | 62 +++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index ea95a1bde82e97a794d2dbe98b2ec7932b641039..71356aaa4dce819754eef54508b1cb62bb1194d7 100644 GIT binary patch delta 236 zcmYk0Jr2S!428u%oPgC!x2mT=;v7-pwwBVkO40%oV#o}a;Q-z_0LLL!7dAiXz0cqG zS$tl_%im8FG<#EN?jWEa(F1k8#SUFmk=TK92Jjlug`7&bP;4Q#2n{O>Tti;wenhBI z#la)=%2T|}#Xo!r%38RzWD%4xgF(g%D9Hv5QZ|V=wYIi(0dw{&d21T+11nx gem3KNnuY2iNft?#NmfbLNj6EgNp?y0Z#f*#Kl{sC^8f$< delta 129 zcmX>zLG?zz>VzWyw4&5hh5UllJcZ)?(xT*4h2qqlw2b`XlEkE(RE3nx;^h3I6ousc z+=9fCOps7=Mq-JMLRo$$P;Fvfib7dtN@~7BK~7>xT7FS(vngY{DI*9o0WmWWvj8zG S5VHX>I}mehH)Z4$cLxANt|~GB diff --git a/scripts/openapi.js b/scripts/openapi.js index 8258a76c..225c5175 100644 --- a/scripts/openapi.js +++ b/scripts/openapi.js @@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + 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 by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -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 || "", - content: { - "application/json": { - schema: schema, - }, - }, - } - : { - description: "No description available", - }), - }, - }.merge(obj.responses); + for (const [k, v] of Object.entries(route.responses)) { + if (v.body) + obj.responses[k] = { + description: obj?.responses?.[k]?.description || "", + content: { + "application/json": { + schema: { + $ref: `#/components/schemas/${v.body}`, + }, + }, + }, + }; + else + obj.responses[k] = { + description: + obj?.responses?.[k]?.description || + "No description available", + }; } } else { obj.responses = { From d1fe2914180c4d03537f8bd0b77190366296c7e0 Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:19:33 +0200 Subject: [PATCH 3/3] Highlight sb-only routes --- assets/openapi.json | Bin 608332 -> 610698 bytes scripts/openapi.js | 26 +++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index 71356aaa4dce819754eef54508b1cb62bb1194d7..fcfc9aac7ee51cb41c7e0e17e1fdef583a812316 100644 GIT binary patch delta 978 zcmX>zLA7hKYC{WS3sVbo3(FSPC*{)xmaz!4SLh}srlhA%Z!~8$o&2Gdjo(T^DYzgp zIW;M{Nhc)EfZtIBqc3RYo8Y8Yf+$vQ=j z8U}rz&ML@Bp+Nh{DHteVs?sD1q^ zRv=~rV)pIpS8;HAQWjLx3-mZux8MKFp~^}PgEW6~gz!_tphX;#8_3f@2g-HW`r0Nu+jG0ZFAgu(tqPo# g{L_I<&FvKeoB?(a;}`jJ3V|(^;NVgKf?BRx0O-Fpa{vGU diff --git a/scripts/openapi.js b/scripts/openapi.js index 225c5175..62623800 100644 --- a/scripts/openapi.js +++ b/scripts/openapi.js @@ -114,7 +114,7 @@ function getTag(key) { return key.match(/\/([\w-]+)/)[1]; } -function apiRoutes() { +function apiRoutes(missingRoutes) { const routes = getRouteDescriptions(); // populate tags @@ -214,6 +214,15 @@ function apiRoutes() { obj.tags = [...(obj.tags || []), getTag(p)].unique(); + if (missingRoutes.additional.includes(path.replace(/\/$/, ""))) { + obj["x-badges"] = [ + { + label: "Spacebar-only", + color: "red", + }, + ]; + } + specification.paths[path] = Object.assign( specification.paths[path] || {}, { @@ -223,10 +232,21 @@ function apiRoutes() { }); } -function main() { +async function main() { console.log("Generating OpenAPI Specification..."); + + const routesRes = await fetch( + "https://github.com/spacebarchat/missing-routes/raw/main/missing.json", + { + headers: { + Accept: "application/json", + }, + }, + ); + const missingRoutes = await routesRes.json(); + combineSchemas(schemas); - apiRoutes(); + apiRoutes(missingRoutes); fs.writeFileSync( openapiPath,