fix: fix type error by handling array of types in JSON schema validation
This commit is contained in:
parent
1b03d1cfe1
commit
cc3f9df33c
1 changed files with 12 additions and 2 deletions
|
|
@ -15,12 +15,22 @@ interface DynamicJsonFormProps {
|
||||||
maxDepth?: number;
|
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 isSimpleObject = (schema: JsonSchemaType): boolean => {
|
||||||
const supportedTypes = ["string", "number", "integer", "boolean", "null"];
|
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") {
|
if (schema.type === "object") {
|
||||||
return Object.values(schema.properties ?? {}).every(
|
return Object.values(schema.properties ?? {}).every(
|
||||||
(prop) => prop.type && supportedTypes.includes(prop.type),
|
(prop) => prop.type && isTypeSupported(prop.type, supportedTypes),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (schema.type === "array") {
|
if (schema.type === "array") {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue