diff --git a/assets/openapi.json b/assets/openapi.json index eb4c799c8..fd4dbb9d3 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index 2d15f13c7..7ffe6a75e 100644 Binary files a/assets/schemas.json and b/assets/schemas.json differ diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 46c4469a1..9ef568245 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -64,6 +64,7 @@ import { ChannelType, DefaultUserGuildSettings, DMChannel, + getInvalidSchemaValues, IdentifySchema, PrivateStatus, PrivateUserProjection, @@ -94,6 +95,12 @@ export async function onIdentify(this: WebSocket, data: Payload) { data.d = validateSchema("IdentifySchema", data.d); } catch (e) { console.error("AJV validation of Identify schema failed:", e); + console.error("Provided values:"); + if (Array.isArray(e)) + for (const invalidSchemaValue of getInvalidSchemaValues(data.d, e)) { + console.error(`${invalidSchemaValue.instancePath}:`, invalidSchemaValue.value); + } + check.call(this, IdentifySchema, data.d); } diff --git a/src/schemas/Validator.ts b/src/schemas/Validator.ts index 610f827c7..8052a9479 100644 --- a/src/schemas/Validator.ts +++ b/src/schemas/Validator.ts @@ -20,6 +20,7 @@ import Ajv, { SchemaObject } from "ajv"; import addFormats from "ajv-formats"; import fs from "node:fs"; import path from "node:path"; +import instance from "@spacebar/api/routes/policies/instance"; const SchemaPath = path.join(__dirname, "..", "..", "assets", "schemas.json"); const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" }).replaceAll("#/definitions/", "")); @@ -67,3 +68,14 @@ export function validateSchema(schema: string, data: G): G { } return data; } + +export function getInvalidSchemaValues(data: object, errors: typeof ajv.errors) { + if (errors == null) return []; + return errors.map((e) => getInvalidSchemaValue(data, e.instancePath)); +} + +function getInvalidSchemaValue(data: object, instancePath: string) { + const actualInstancePath = instancePath.startsWith("/") ? instancePath.slice(1) : instancePath; + if (actualInstancePath.includes("/")) return getInvalidSchemaValue(data, actualInstancePath.split("/")[0]); + return { instancePath, value: data }; +}