docs: fix parameters display in module reference (#5425)

* prettify json output

* fix parameter optional + array children
This commit is contained in:
Shahed Nasser
2023-10-19 19:34:17 +03:00
committed by GitHub
parent c28935b4e8
commit 28d2f2ea98
6 changed files with 37 additions and 20 deletions

View File

@@ -15,7 +15,9 @@ export default function (theme: MarkdownTheme) {
).map((parameter) => reflectionComponentFormatter(parameter, 1))
return `<${parameterComponent} parameters={${JSON.stringify(
parameters
parameters,
null,
2
)}} />`
}
)

View File

@@ -40,7 +40,9 @@ function getReturnFromType(
if (parameterStyle === "component") {
return `<${parameterComponent} parameters={${JSON.stringify(
componentItems
componentItems,
null,
2
)}} />`
} else {
return formatReturnAsList(componentItems)
@@ -90,7 +92,9 @@ function getReturnFromComment(theme: MarkdownTheme, comment: Comment) {
result +=
parameterStyle === "component"
? `\n\n<${parameterComponent} parameters={${JSON.stringify(
content
content,
null,
2
)}} title={"${commentPart.target.name}"} />\n\n`
: `\n\n<details>\n<summary>\n${
commentPart.target.name

View File

@@ -58,7 +58,11 @@ function getComponentMarkdownContent(
reflectionFormatter(property, "component")
)
return `<${parameterComponent} parameters={${JSON.stringify(parameters)}} />`
return `<${parameterComponent} parameters={${JSON.stringify(
parameters,
null,
2
)}} />`
}
function getTableMarkdownContent(

View File

@@ -13,7 +13,9 @@ export default function (theme: MarkdownTheme) {
)
return `<${parameterComponent} parameters={${JSON.stringify(
parameters
parameters,
null,
2
)}} />`
}
)

View File

@@ -85,7 +85,8 @@ export function reflectionComponentFormatter(
level = 1
): Parameter {
const defaultValue = getDefaultValue(reflection) || ""
const optional = reflection.flags.isOptional
const optional =
reflection.flags.isOptional || reflection.kind === ReflectionKind.EnumMember
const comments = getComments(reflection)
const componentItem: Parameter = {
name: reflection.name,

View File

@@ -56,23 +56,27 @@ export function returnReflectionComponentFormatter(
}
})
}
} else if (reflectionType.reflection) {
componentItem.push(
reflectionComponentFormatter(
reflectionType.reflection as DeclarationReflection,
level
)
)
} else {
// try to retrieve reflection by its name
const reflection = project.getChildByName(reflectionType.name)
const reflection = (reflectionType.reflection ||
project.getChildByName(reflectionType.name)) as DeclarationReflection
if (reflection) {
componentItem.push(
reflectionComponentFormatter(
reflection as DeclarationReflection,
level
if (reflection.children?.length) {
reflection.children.forEach((childItem) => {
componentItem.push(
reflectionComponentFormatter(
childItem as DeclarationReflection,
level
)
)
})
} else {
componentItem.push(
reflectionComponentFormatter(
reflection as DeclarationReflection,
level
)
)
)
}
}
}
} else if (reflectionType.type === "array") {