docgen: add support for intersection types
This commit is contained in:
@@ -61,12 +61,16 @@ export default class ApiDocGenerator {
|
||||
|
||||
const id = this.getObjectPropertyLiteral(info, 'id');
|
||||
const description = this.getObjectPropertyLiteral(info, 'description');
|
||||
const interfaceInfo = this.getInterfaceInfo(typeArgs[0]);
|
||||
if (!interfaceInfo) {
|
||||
throw new Error('api has no info type argument');
|
||||
}
|
||||
|
||||
return { id, name, source, description, interfaceInfo };
|
||||
const rootTypeNode = typeArgs[0];
|
||||
const typeNodes = ts.isIntersectionTypeNode(rootTypeNode)
|
||||
? rootTypeNode.types.slice()
|
||||
: [rootTypeNode];
|
||||
const interfaceInfos = typeNodes.map(typeNode =>
|
||||
this.getInterfaceInfo(typeNode),
|
||||
);
|
||||
|
||||
return { id, name, source, description, interfaceInfos };
|
||||
}
|
||||
|
||||
private getNodeDocs(node: ts.Node): string[] {
|
||||
|
||||
@@ -47,9 +47,9 @@ export default class ApiDocPrinter {
|
||||
// Remove line numbers from codeblocks
|
||||
printer.style('.linenodiv{ display: none }');
|
||||
|
||||
printer.header(1, `shared/apis/${apiDoc.id}`);
|
||||
printer.header(1, apiDoc.id);
|
||||
|
||||
const ifInfo = apiDoc.interfaceInfo;
|
||||
const ifInfo = apiDoc.interfaceInfos[0];
|
||||
|
||||
if (ifInfo.docs.length) {
|
||||
for (const doc of ifInfo.docs) {
|
||||
|
||||
@@ -77,7 +77,7 @@ export type ApiDoc = {
|
||||
name: string;
|
||||
source: ts.SourceFile;
|
||||
description: string;
|
||||
interfaceInfo: InterfaceInfo;
|
||||
interfaceInfos: InterfaceInfo[];
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user