module manager: use json schema field for additional validation

This commit is contained in:
dswbx
2024-12-05 09:50:25 +01:00
parent 3757157a06
commit a3348122e6
2 changed files with 31 additions and 10 deletions

View File

@@ -54,7 +54,7 @@ export class JsonSchemaField<
if (parentValid) {
// already checked in parent
if (!value || typeof value !== "object") {
if (!this.isRequired() && (!value || typeof value !== "object")) {
//console.log("jsonschema:valid: not checking", this.name, value, context);
return true;
}
@@ -65,6 +65,7 @@ export class JsonSchemaField<
} else {
//console.log("jsonschema:invalid", this.name, value, context);
}
//console.log("jsonschema:invalid:fromParent", this.name, value, context);
return false;
}
@@ -110,9 +111,13 @@ export class JsonSchemaField<
): Promise<string | undefined> {
const value = await super.transformPersist(_value, em, context);
if (this.nullish(value)) return value;
//console.log("jsonschema:transformPersist", this.name, _value, context);
if (!this.isValid(value)) {
//console.error("jsonschema:transformPersist:invalid", this.name, value);
throw new TransformPersistFailedException(this.name, value);
} else {
//console.log("jsonschema:transformPersist:valid", this.name, value);
}
if (!value || typeof value !== "object") return this.getDefault();