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
@@ -15,7 +15,9 @@ export default function (theme: MarkdownTheme) {
).map((parameter) => reflectionComponentFormatter(parameter, 1)) ).map((parameter) => reflectionComponentFormatter(parameter, 1))
return `<${parameterComponent} parameters={${JSON.stringify( return `<${parameterComponent} parameters={${JSON.stringify(
parameters parameters,
null,
2
)}} />` )}} />`
} }
) )
@@ -40,7 +40,9 @@ function getReturnFromType(
if (parameterStyle === "component") { if (parameterStyle === "component") {
return `<${parameterComponent} parameters={${JSON.stringify( return `<${parameterComponent} parameters={${JSON.stringify(
componentItems componentItems,
null,
2
)}} />` )}} />`
} else { } else {
return formatReturnAsList(componentItems) return formatReturnAsList(componentItems)
@@ -90,7 +92,9 @@ function getReturnFromComment(theme: MarkdownTheme, comment: Comment) {
result += result +=
parameterStyle === "component" parameterStyle === "component"
? `\n\n<${parameterComponent} parameters={${JSON.stringify( ? `\n\n<${parameterComponent} parameters={${JSON.stringify(
content content,
null,
2
)}} title={"${commentPart.target.name}"} />\n\n` )}} title={"${commentPart.target.name}"} />\n\n`
: `\n\n<details>\n<summary>\n${ : `\n\n<details>\n<summary>\n${
commentPart.target.name commentPart.target.name
@@ -58,7 +58,11 @@ function getComponentMarkdownContent(
reflectionFormatter(property, "component") reflectionFormatter(property, "component")
) )
return `<${parameterComponent} parameters={${JSON.stringify(parameters)}} />` return `<${parameterComponent} parameters={${JSON.stringify(
parameters,
null,
2
)}} />`
} }
function getTableMarkdownContent( function getTableMarkdownContent(
@@ -13,7 +13,9 @@ export default function (theme: MarkdownTheme) {
) )
return `<${parameterComponent} parameters={${JSON.stringify( return `<${parameterComponent} parameters={${JSON.stringify(
parameters parameters,
null,
2
)}} />` )}} />`
} }
) )
@@ -85,7 +85,8 @@ export function reflectionComponentFormatter(
level = 1 level = 1
): Parameter { ): Parameter {
const defaultValue = getDefaultValue(reflection) || "" const defaultValue = getDefaultValue(reflection) || ""
const optional = reflection.flags.isOptional const optional =
reflection.flags.isOptional || reflection.kind === ReflectionKind.EnumMember
const comments = getComments(reflection) const comments = getComments(reflection)
const componentItem: Parameter = { const componentItem: Parameter = {
name: reflection.name, name: reflection.name,
@@ -56,23 +56,27 @@ export function returnReflectionComponentFormatter(
} }
}) })
} }
} else if (reflectionType.reflection) {
componentItem.push(
reflectionComponentFormatter(
reflectionType.reflection as DeclarationReflection,
level
)
)
} else { } else {
// try to retrieve reflection by its name const reflection = (reflectionType.reflection ||
const reflection = project.getChildByName(reflectionType.name) project.getChildByName(reflectionType.name)) as DeclarationReflection
if (reflection) { if (reflection) {
componentItem.push( if (reflection.children?.length) {
reflectionComponentFormatter( reflection.children.forEach((childItem) => {
reflection as DeclarationReflection, componentItem.push(
level reflectionComponentFormatter(
childItem as DeclarationReflection,
level
)
)
})
} else {
componentItem.push(
reflectionComponentFormatter(
reflection as DeclarationReflection,
level
)
) )
) }
} }
} }
} else if (reflectionType.type === "array") { } else if (reflectionType.type === "array") {