mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-16 19:15:03 +00:00
fix: config schema in docs
This commit is contained in:
parent
36ce6903a3
commit
6a2e9fda0f
1 changed files with 7 additions and 8 deletions
|
@ -4,6 +4,7 @@ import { availableGuildPlugins } from "../plugins/availablePlugins.js";
|
||||||
import { ZeppelinGuildPluginInfo } from "../types.js";
|
import { ZeppelinGuildPluginInfo } from "../types.js";
|
||||||
import { indentLines } from "../utils.js";
|
import { indentLines } from "../utils.js";
|
||||||
import { notFound } from "./responses.js";
|
import { notFound } from "./responses.js";
|
||||||
|
import { $ZodPipeDef } from "zod/v4/core";
|
||||||
|
|
||||||
function isZodObject(schema: z.ZodType): schema is z.ZodObject<any> {
|
function isZodObject(schema: z.ZodType): schema is z.ZodObject<any> {
|
||||||
return schema.def.type === "object";
|
return schema.def.type === "object";
|
||||||
|
@ -45,7 +46,7 @@ function formatZodConfigSchema(schema: z.ZodType) {
|
||||||
if (isZodObject(schema)) {
|
if (isZodObject(schema)) {
|
||||||
return (
|
return (
|
||||||
`{\n` +
|
`{\n` +
|
||||||
Object.entries(schema._def.shape())
|
Object.entries(schema.def.shape)
|
||||||
.map(([k, value]) => indentLines(`${k}: ${formatZodConfigSchema(value as z.ZodType)}`, 2))
|
.map(([k, value]) => indentLines(`${k}: ${formatZodConfigSchema(value as z.ZodType)}`, 2))
|
||||||
.join("\n") +
|
.join("\n") +
|
||||||
"\n}"
|
"\n}"
|
||||||
|
@ -61,7 +62,7 @@ function formatZodConfigSchema(schema: z.ZodType) {
|
||||||
return `Array<${formatZodConfigSchema(schema.def.element)}>`;
|
return `Array<${formatZodConfigSchema(schema.def.element)}>`;
|
||||||
}
|
}
|
||||||
if (isZodUnion(schema)) {
|
if (isZodUnion(schema)) {
|
||||||
return schema._def.options.map((t) => formatZodConfigSchema(t)).join(" | ");
|
return schema.def.options.map((t) => formatZodConfigSchema(t)).join(" | ");
|
||||||
}
|
}
|
||||||
if (isZodNullable(schema)) {
|
if (isZodNullable(schema)) {
|
||||||
return `Nullable<${formatZodConfigSchema(schema.def.innerType)}>`;
|
return `Nullable<${formatZodConfigSchema(schema.def.innerType)}>`;
|
||||||
|
@ -90,6 +91,9 @@ function formatZodConfigSchema(schema: z.ZodType) {
|
||||||
if (schema.def.type === "never") {
|
if (schema.def.type === "never") {
|
||||||
return "never";
|
return "never";
|
||||||
}
|
}
|
||||||
|
if (schema.def.type === "pipe") {
|
||||||
|
return formatZodConfigSchema((schema.def as $ZodPipeDef).in as z.ZodType);
|
||||||
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,12 +127,7 @@ export function initDocs(router: express.Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { configSchema, ...info } = pluginInfo.docs;
|
const { configSchema, ...info } = pluginInfo.docs;
|
||||||
let formattedConfigSchema: string;
|
const formattedConfigSchema = formatZodConfigSchema(configSchema);
|
||||||
try {
|
|
||||||
formattedConfigSchema = JSON.stringify(z.toJSONSchema(configSchema), null, 2);
|
|
||||||
} catch (err) {
|
|
||||||
formattedConfigSchema = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
const messageCommands = (pluginInfo.plugin.messageCommands || []).map((cmd) => ({
|
const messageCommands = (pluginInfo.plugin.messageCommands || []).map((cmd) => ({
|
||||||
trigger: cmd.trigger,
|
trigger: cmd.trigger,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue