diff --git a/src/api/docs.ts b/src/api/docs.ts index 09b57185..1e847617 100644 --- a/src/api/docs.ts +++ b/src/api/docs.ts @@ -17,43 +17,21 @@ function formatConfigSchema(schema) { ); } else if (schema._tag === "DictionaryType") { return "{\n" + indentLines(`[string]: ${formatConfigSchema(schema.codomain)}`, 2) + "\n}"; + } else if (schema._tag === "ArrayType") { + return `Array<${formatConfigSchema(schema.type)}>`; + } else if (schema._tag === "UnionType") { + if (schema.name.startsWith("Nullable<")) { + return `Nullable<${formatConfigSchema(schema.types[0])}>`; + } else { + return schema.types.map(t => formatConfigSchema(t)).join(" | "); + } + } else if (schema._tag === "IntersectionType") { + return schema.types.map(t => formatConfigSchema(t)).join(" & "); } else { return schema.name; } } -function formatTypeName(typeName) { - let result = ""; - let indent = 0; - let skip = false; - for (const char of [...typeName]) { - if (skip) { - skip = false; - continue; - } - - if (char === "}") { - result += "\n"; - indent--; - skip = true; - } - - result += char; - - if (char === "{") { - result += "\n"; - indent++; - skip = true; - } - - if (char === ",") { - result += "\n"; - skip = true; - } - } - return result; -} - export function initDocs(app: express.Express) { const docsPlugins = availablePlugins.filter(pluginClass => pluginClass.showInDocs); @@ -106,7 +84,7 @@ export function initDocs(app: express.Express) { return arr; }, []); - const options = (pluginClass as typeof ZeppelinPlugin).getStaticDefaultOptions(); + const defaultOptions = (pluginClass as typeof ZeppelinPlugin).getStaticDefaultOptions(); const configSchema = pluginClass.configSchema && formatConfigSchema(pluginClass.configSchema); @@ -114,7 +92,7 @@ export function initDocs(app: express.Express) { name: pluginClass.pluginName, info: pluginClass.pluginInfo || {}, configSchema, - options, + defaultOptions, commands, }); }); diff --git a/src/utils.ts b/src/utils.ts index f57367f8..3decab7b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -39,7 +39,7 @@ export const HOURS = 60 * MINUTES; export const DAYS = 24 * HOURS; export function tNullable>(type: T) { - return t.union([type, t.undefined, t.null], type.name); + return t.union([type, t.undefined, t.null], `Nullable<${type.name}>`); } export function dropPropertiesByName(obj, propName) {