/
generate_options_schema.js
69 lines (59 loc) · 2.33 KB
/
generate_options_schema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//@ts-check
const { addTypeDocOptions } = require("../dist/lib/utils/options/sources");
const { ParameterType } = require("../dist");
const IGNORED_OPTIONS = new Set(["help", "version"]);
const IGNORED_DEFAULT_OPTIONS = new Set(["options", "tsconfig"]);
const schema = {
$schema: "https://json-schema.org/draft/2019-09/schema",
title: "JSON Schema for typedoc.json",
type: "object",
properties: {},
};
addTypeDocOptions({
/** @param {import("../dist").DeclarationOption} option */
addDeclaration(option) {
if (IGNORED_OPTIONS.has(option.name)) return;
const data = {
description: option.help,
};
switch (option.type ?? ParameterType.String) {
case ParameterType.Array:
data.type = "array";
data.items = { type: "string" };
data.default = option.defaultValue ?? [];
break;
case ParameterType.String:
data.type = "string";
if (!IGNORED_DEFAULT_OPTIONS.has(option.name)) {
data.default = option.defaultValue ?? "";
}
break;
case ParameterType.Boolean:
data.type = "boolean";
data.default = option.defaultValue ?? false;
break;
case ParameterType.Number: {
const decl = /** @type {import("../dist").NumberDeclarationOption} */ (option);
data.type = "number";
data.default = decl.defaultValue ?? 0;
data.maximum = decl.maxValue;
data.minimum = decl.minValue;
break;
}
case ParameterType.Map: {
const map = /** @type {import("../dist").MapDeclarationOption} */ (option)
.map;
data.enum =
map instanceof Map ? [...map.keys()] : Object.keys(map);
data.default = option.defaultValue;
break;
}
case ParameterType.Mixed:
break; // Nothing to do... TypeDoc really shouldn't have any of these.
}
schema.properties[option.name] = data;
},
});
schema.properties.logger.enum = ["console", "none"];
schema.properties.logger.default = "console";
console.log(JSON.stringify(schema, null, "\t"));