Skip to content

Commit

Permalink
fix: eject document for nested type in function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterLuffy authored and PengJiyuan committed Aug 10, 2022
1 parent d6e3424 commit 6c56659
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,33 @@ function getPropertySchema(
// Get Json schema of Function
function getFunctionSchema(
declaration: FunctionDeclaration,
strictComment = false
strictComment = false,
nestedTypeList: SchemaList,
parsedNestedTypeSet: Set<Type>,
linkFormatter: LinkFormatter
): Pick<FunctionSchema, 'params' | 'returns'> {
return {
params: declaration.getParameters().map((para) => {
const tags = getSymbolTags(para.getSymbol() as Symbol, strictComment);

let typeWithLink = para
.getType()
.getText()
.replace(/import\([^)]+\)\./g, '');

// Deeply analyze nested types
dumpNestedTypes(para, nestedTypeList, parsedNestedTypeSet);
typeWithLink = getDisplayTypeWithLink(
typeWithLink,
nestedTypeList,
parsedNestedTypeSet,
linkFormatter
);

return {
tags,
name: para.getName(),
type: para.getType().getText(),
type: typeWithLink,
isOptional: para.isOptional(),
initializerText:
para.getInitializer()?.getText() ||
Expand Down Expand Up @@ -399,7 +417,13 @@ function generateSchema(sourceFile: SourceFile, typeChecker: TypeChecker, config
) {
schema = {
tags,
...getFunctionSchema(typeNode as FunctionDeclaration),
...getFunctionSchema(
typeNode as FunctionDeclaration,
strictComment,
nestedTypeList,
parsedNestedTypeSet,
linkFormatter
),
};
}
// Interface declaration forbid extends
Expand Down

0 comments on commit 6c56659

Please sign in to comment.