Skip to content

Commit

Permalink
Fix display of array items in Schema component
Browse files Browse the repository at this point in the history
This commit changes the display of array items so that the actual sub-schema of
said items is displayed.

This reduces the asthetic annoyance when an empty "Array[]" schema is displayed
(when no sub-schema is given), and also fixes a bug where the description of
array items was not rendered at all.
  • Loading branch information
martin-helmich committed Jul 2, 2024
1 parent d706cb6 commit 69c5ce2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/openapi/OperationInputValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function ArrayValue({ schema }: { schema: OpenAPIV3.SchemaObject }) {
<span className={styles.parameterAlternative}>Array[</span>
</div>
<div className={styles.parameterListBody}>{body}</div>
<Schema schema={schema} />
<PropertyValue name="*" schema={schema} required={false} />
<div className={styles.parameterListHeader}>
<span className={styles.parameterAlternative}>]</span>
</div>
Expand All @@ -58,6 +58,8 @@ export function PropertyValue({
body = <Markdown>{schema.description}</Markdown>;
}

const hasSubSchema = schema.properties || schema.additionalProperties || schema.items;

return (
<li key={name}>
<div className={styles.parameterListHeader}>
Expand All @@ -67,7 +69,7 @@ export function PropertyValue({
{requiredOrOptional}
</div>
<div className={styles.parameterListBody}>{body}</div>
<Schema schema={schema} />
{hasSubSchema && <Schema schema={schema} />}
</li>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/openapi/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ export default function Schema({ schema }: Props) {
if (schema.type === "array") {
return <ArraySchema schema={schema} />;
}

return <PropertyValue name="*" schema={schema} required={false} />;
}

0 comments on commit 69c5ce2

Please sign in to comment.