NEW: doc for enums
@@ -69,7 +69,11 @@ export function typeName(fullName: string) {
}
function jsDocStart(element: Documented, indent: string = ""): string {
- let ts = `\n${indent}/**`;
+ return `\n${indent}/**${jsDocNext(element, indent)}`;
+}
+
+function jsDocNext(element: Documented, indent: string = ""): string {
+ let ts = "";
if (element.summary) {
ts += jsDoc(element.summary, indent);
}
@@ -90,7 +94,26 @@ function jsDocEnd(indent: string = ""): string {
}
function elementJsDoc(element: Documented, indent: string = ""): string {
- return `${jsDocStart(element, indent)}${jsDocEnd(indent)}`;
+ return element.summary || element.description ?
+ `${jsDocStart(element, indent)}${jsDocEnd(indent)}`
+ : "";
+}
+
+function enumOfTypesJsDoc(type: ApiEnumOfTypes, indent = "") {
+ let ts = jsDocStart(type);
+ ts += jsDoc("\nDepends on `type` field.\n", indent);
+ for (const variant of type.enum_types) {
+ ts += jsDoc(`\n### \`${variant.name}\`\n`, indent);
+ if (variant.summary) {
+ ts += jsDoc(variant.summary, indent);
+ }
+ if (variant.description) {
+ ts += jsDoc("", indent);
+ ts += jsDoc(variant.description, indent);
+ }
+ }
+ ts += jsDocEnd(indent);
+ return ts;
}
function getRefName(type: ApiType): string {
@@ -106,6 +129,12 @@ export class TSCode extends Code {
let ts = `// ${module.name} module\n\n`;
for (const type of module.types) {
+ if (type.type === ApiTypeIs.EnumOfTypes) {
+ ts += enumOfTypesJsDoc(type);
+ } else {
+ ts += elementJsDoc(type);
+ }
+
ts += `\nexport ${this.typeDef(type, true)}`;
if (type.type === ApiTypeIs.EnumOfTypes) {
ts += this.typeVariantConstructors(type.name, type);
@@ -232,7 +261,11 @@ export class ${Code.upperFirst(module.name)}Module {
case ApiTypeIs.Array:
return `${this.type(type.array_item, indent)}[]`;
case ApiTypeIs.EnumOfConsts:
- const variants = type.enum_consts.map(c => this.constVariant(c, `${indent} `, includeDoc));
+ const variants = type.enum_consts.map(c => this.constVariant(
+ c,
+ `${indent} `,
+ includeDoc,
+ ));
return `{\n${variants.join(",\n")}\n${indent}}`;
case ApiTypeIs.BigInt:
return "bigint";
@@ -250,7 +283,9 @@ export class ${Code.upperFirst(module.name)}Module {
}
typeDef(type: ApiField, includeDoc?: boolean): string {
- const decl = type.type === ApiTypeIs.EnumOfConsts ? `enum ${type.name}` : `type ${type.name} =`;
+ const decl = type.type === ApiTypeIs.EnumOfConsts
+ ? `enum ${type.name}`
+ : `type ${type.name} =`;
return `${decl} ${this.type(type, "", includeDoc)}\n`;
}
