Fix ignored request schemas

This commit is contained in:
Rory& 2025-10-02 19:29:49 +02:00
parent 9ef9744332
commit efba3f245d
3 changed files with 47 additions and 4 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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;

View File

@ -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<

View File

@ -46,9 +46,6 @@ export const ajv = new Ajv({
addFormats(ajv);
export function validateSchema<G extends object>(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)