diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index eeb5035e..ca708585 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -121,7 +121,7 @@ function Body({ type, optional, node, ctx }: Props) { return <> } return
- +
} if (type.kind === 'tuple') { @@ -849,7 +849,7 @@ function ListHead({ type, node, ctx }: Props) { } -function ListBody({ type: outerType, node, ctx }: Props) { +function ListBody({ type: outerType, optional, node, ctx }: Props) { if (!JsonArrayNode.is(node)) { return <> } @@ -892,6 +892,21 @@ function ListBody({ type: outerType, node, ctx }: Props { + ctx.makeEdit(() => { + const newNode = edit(node.range) + if (JsonArrayNode.is(newNode) && newNode.children.length === 0 && optional && type.kind === 'list' && (type.lengthRange?.min ?? 0) > 0) { + // Remove entire list when empty list is not allowed and field is optional + return undefined + } + return newNode + }) + }, [ctx, node, optional, type]) + + const listCtx = useMemo(() => { + return { ...ctx, makeEdit: makeListEdit } + }, [ctx, makeListEdit]) + return <> {node.children.map((item, index) => { if (index === maxShown) { @@ -905,7 +920,7 @@ function ListBody({ type: outerType, node, ctx }: Props } const key = index.toString() - return + return })} {node.children.length > 0 &&