Skip to content

Commit cc3f9df

Browse files
committed
fix: fix type error by handling array of types in JSON schema validation
1 parent 1b03d1c commit cc3f9df

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

client/src/components/DynamicJsonForm.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ interface DynamicJsonFormProps {
1515
maxDepth?: number;
1616
}
1717

18+
const isTypeSupported = (
19+
type: JsonSchemaType["type"],
20+
supportedTypes: string[],
21+
): boolean => {
22+
if (Array.isArray(type)) {
23+
return type.every((t) => supportedTypes.includes(t));
24+
}
25+
return typeof type === "string" && supportedTypes.includes(type);
26+
};
27+
1828
const isSimpleObject = (schema: JsonSchemaType): boolean => {
1929
const supportedTypes = ["string", "number", "integer", "boolean", "null"];
20-
if (schema.type && supportedTypes.includes(schema.type)) return true;
30+
if (schema.type && isTypeSupported(schema.type, supportedTypes)) return true;
2131
if (schema.type === "object") {
2232
return Object.values(schema.properties ?? {}).every(
23-
(prop) => prop.type && supportedTypes.includes(prop.type),
33+
(prop) => prop.type && isTypeSupported(prop.type, supportedTypes),
2434
);
2535
}
2636
if (schema.type === "array") {

0 commit comments

Comments
 (0)