From 6a2e9fda0fb31824ea2227a4ec3f8b0804faa251 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 1 Jun 2025 01:03:23 +0000 Subject: [PATCH] fix: config schema in docs --- backend/src/api/docs.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/src/api/docs.ts b/backend/src/api/docs.ts index 96769941..59aef88b 100644 --- a/backend/src/api/docs.ts +++ b/backend/src/api/docs.ts @@ -4,6 +4,7 @@ import { availableGuildPlugins } from "../plugins/availablePlugins.js"; import { ZeppelinGuildPluginInfo } from "../types.js"; import { indentLines } from "../utils.js"; import { notFound } from "./responses.js"; +import { $ZodPipeDef } from "zod/v4/core"; function isZodObject(schema: z.ZodType): schema is z.ZodObject { return schema.def.type === "object"; @@ -45,7 +46,7 @@ function formatZodConfigSchema(schema: z.ZodType) { if (isZodObject(schema)) { return ( `{\n` + - Object.entries(schema._def.shape()) + Object.entries(schema.def.shape) .map(([k, value]) => indentLines(`${k}: ${formatZodConfigSchema(value as z.ZodType)}`, 2)) .join("\n") + "\n}" @@ -61,7 +62,7 @@ function formatZodConfigSchema(schema: z.ZodType) { return `Array<${formatZodConfigSchema(schema.def.element)}>`; } if (isZodUnion(schema)) { - return schema._def.options.map((t) => formatZodConfigSchema(t)).join(" | "); + return schema.def.options.map((t) => formatZodConfigSchema(t)).join(" | "); } if (isZodNullable(schema)) { return `Nullable<${formatZodConfigSchema(schema.def.innerType)}>`; @@ -90,6 +91,9 @@ function formatZodConfigSchema(schema: z.ZodType) { if (schema.def.type === "never") { return "never"; } + if (schema.def.type === "pipe") { + return formatZodConfigSchema((schema.def as $ZodPipeDef).in as z.ZodType); + } return "unknown"; } @@ -123,12 +127,7 @@ export function initDocs(router: express.Router) { } const { configSchema, ...info } = pluginInfo.docs; - let formattedConfigSchema: string; - try { - formattedConfigSchema = JSON.stringify(z.toJSONSchema(configSchema), null, 2); - } catch (err) { - formattedConfigSchema = ""; - } + const formattedConfigSchema = formatZodConfigSchema(configSchema); const messageCommands = (pluginInfo.plugin.messageCommands || []).map((cmd) => ({ trigger: cmd.trigger,