3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

docs api: plugin options -> defaultOptions, tweak config schema formatting

This commit is contained in:
Dragory 2019-09-29 15:54:19 +03:00
parent 3ff3bfd5f0
commit 86b1df0a6a
2 changed files with 13 additions and 35 deletions

View file

@ -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,
});
});

View file

@ -39,7 +39,7 @@ export const HOURS = 60 * MINUTES;
export const DAYS = 24 * HOURS;
export function tNullable<T extends t.Type<any, any, unknown>>(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) {