From efba3f245dc9694187ee5143410ce1fb18cd7302 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 2 Oct 2025 19:29:49 +0200 Subject: [PATCH] Fix ignored request schemas --- src/api/routes/reporting/menu/message.ts | 40 ++++++++++++++++++++++++ src/api/util/handlers/route.ts | 8 ++++- src/util/schemas/Validator.ts | 3 -- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/api/routes/reporting/menu/message.ts diff --git a/src/api/routes/reporting/menu/message.ts b/src/api/routes/reporting/menu/message.ts new file mode 100644 index 00000000..fcf02ff8 --- /dev/null +++ b/src/api/routes/reporting/menu/message.ts @@ -0,0 +1,40 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2025 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 . +*/ + +import { route } from "@spacebar/api"; +import { Request, Response, Router } from "express"; +import { CollectiblesCategoriesResponse } from "@spacebar/util"; + +const router = Router({ mergeParams: true }); + +router.get( + "/", + route({ + responses: { + 200: { + body: "ReportingMenuResponse", + }, + 204: {}, + }, + }), + (req: Request, res: Response) => { + res.send([] as ReportingMenuResponseSchema); + }, +); + +export default router; diff --git a/src/api/util/handlers/route.ts b/src/api/util/handlers/route.ts index 30ffa2d0..8425b8c2 100644 --- a/src/api/util/handlers/route.ts +++ b/src/api/util/handlers/route.ts @@ -32,6 +32,11 @@ import { import { AnyValidateFunction } from "ajv/dist/core"; import { NextFunction, Request, Response } from "express"; +const ignoredRequestSchemas = [ + // skip validation for settings proto JSON updates - TODO: figure out if this even possible to fix? + "SettingsProtoUpdateJsonSchema" +] + declare global { // TODO: fix this // eslint-disable-next-line @typescript-eslint/no-namespace @@ -119,7 +124,8 @@ export function route(opts: RouteOptions) { } } - if (validate) { + + if (validate && !ignoredRequestSchemas.includes(opts.requestBody!)) { const valid = validate(req.body); if (!valid) { const fields: Record< diff --git a/src/util/schemas/Validator.ts b/src/util/schemas/Validator.ts index 2e5ace41..1d9daf2c 100644 --- a/src/util/schemas/Validator.ts +++ b/src/util/schemas/Validator.ts @@ -46,9 +46,6 @@ export const ajv = new Ajv({ addFormats(ajv); export function validateSchema(schema: string, data: G): G { - // skip validation for settings proto JSON updates - TODO: figure out if this even possible? - if (schema === "SettingsProtoUpdateJsonSchema") return data; - const valid = ajv.validate(schema, data); if (!valid) { console.log("[Validator] Validation error in ", schema)