in docs-sdk/docs-provider/src/type-info-loader/collectInterfaceInfo.ts [57:117]
function collectInterfaceInfo(node: ts.Declaration, symbol: ts.Symbol) {
if (!ts.isInterfaceDeclaration(node))
throw new Error(`target is not an InterfaceDeclaration`);
if (!symbol) throw new Error(`can't find symbol`);
const name = node.name.getText();
const documentation = ts.displayPartsToString(
symbol.getDocumentationComment(checker)
);
const propertiesInfo: InterfacePropertyInfo[] = [];
symbol.members?.forEach((symbol) => {
const name = symbol.name;
const declaration = symbol.valueDeclaration;
if (
!(
declaration &&
(ts.isPropertySignature(declaration) ||
ts.isMethodSignature(declaration))
)
) {
throw new Error(
`unexpected declaration type in interface. name: ${name}, kind: ${
// @ts-ignore
ts.SyntaxKind[declaration.kind]
}`
);
}
const typeText = declaration.type?.getFullText() ?? "";
const documentation = ts.displayPartsToString(
symbol.getDocumentationComment(checker)
);
const defaultValue = (() => {
const jsDoc: ts.JSDoc | undefined = (declaration as any).jsDoc?.[0];
const defaultValueTag = jsDoc?.tags?.find((t) => {
return (
t.tagName.escapedText === "defaultValue" ||
t.tagName.escapedText === "default"
);
});
return defaultValueTag?.comment;
})();
propertiesInfo.push({
name,
typeText,
documentation,
// @ts-ignore
defaultValue,
});
});
const interfaceInfo: InterfaceInfo = {
name,
documentation,
properties: propertiesInfo,
};
return interfaceInfo;
}