fix: fix type error by handling array of types in JSON schema validation

This commit is contained in:
Mats Julius Funke 2025-08-04 09:26:24 +02:00
commit cc3f9df33c
No known key found for this signature in database

View file

@ -15,12 +15,22 @@ interface DynamicJsonFormProps {
maxDepth?: number;
}
const isTypeSupported = (
type: JsonSchemaType["type"],
supportedTypes: string[],
): boolean => {
if (Array.isArray(type)) {
return type.every((t) => supportedTypes.includes(t));
}
return typeof type === "string" && supportedTypes.includes(type);
};
const isSimpleObject = (schema: JsonSchemaType): boolean => {
const supportedTypes = ["string", "number", "integer", "boolean", "null"];
if (schema.type && supportedTypes.includes(schema.type)) return true;
if (schema.type && isTypeSupported(schema.type, supportedTypes)) return true;
if (schema.type === "object") {
return Object.values(schema.properties ?? {}).every(
(prop) => prop.type && supportedTypes.includes(prop.type),
(prop) => prop.type && isTypeSupported(prop.type, supportedTypes),
);
}
if (schema.type === "array") {