Skip to content

Commit c9066e5

Browse files
committed
fix: json schema object render
fixes #246
1 parent a91cae9 commit c9066e5

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed
-16.1 KB
Binary file not shown.

src/JSONSchema/SchemaRenderer.tsx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { JSONSchema4 } from "json-schema";
3-
import { TableRow, TableCell, Typography } from "@material-ui/core";
3+
import { TableRow, TableCell, Typography, Table, TableHead, TableBody } from "@material-ui/core";
44
import JSONSchemaFields from "./fields/JSONSchemaFields";
55
import _ from "lodash";
66
import { grey, green, purple, yellow, blue } from "@material-ui/core/colors";
@@ -104,23 +104,38 @@ const SchemaRenderer: React.FC<IProps> = ({ schema, required, name }) => {
104104
<Typography variant="body1" color="primary">object</Typography>
105105
</TableCell>
106106
<TableCell colSpan={5}>
107-
{schema.properties && Object.entries(schema.properties).map(([n, prop]: [string, JSONSchema4], i: number) => {
108-
return (
109-
<JSONSchemaFields
110-
key={n}
111-
schema={prop}
112-
name={n}
113-
hideHeader={i !== 0}
114-
required={schema.required && schema.required.includes(n)}
115-
/>
116-
);
117-
})}
107+
<Table>
108+
<TableHead>
109+
<TableRow>
110+
<TableCell>Name</TableCell>
111+
<TableCell>Type</TableCell>
112+
<TableCell>Pattern</TableCell>
113+
<TableCell>Required</TableCell>
114+
<TableCell>Description</TableCell>
115+
</TableRow>
116+
</TableHead>
117+
<TableBody>
118+
{schema.properties &&
119+
Object.entries(schema.properties)
120+
.map(([n, prop]: [string, JSONSchema4], i: number) => {
121+
return (
122+
<JSONSchemaFields
123+
key={n}
124+
schema={prop}
125+
name={n}
126+
hideHeader={true}
127+
required={schema.required && schema.required.includes(n)}
128+
/>
129+
);
130+
})}
131+
</TableBody>
132+
</Table>
118133
</TableCell>
119134
</TableRow>
120135
);
121136
}
122137

123-
const colorMap: {[k: string]: string} = {
138+
const colorMap: { [k: string]: string } = {
124139
any: grey[500],
125140
array: blue[300],
126141
boolean: blue[500],

0 commit comments

Comments
 (0)