Hi, i am currently trying to implement a special validation box in our code. When a value in the form changes and a validation rule with a special annotation would fire i want to display it as a global error. I already have the code that validates my current document and returns the errors. For those errors I want to check if the rule has the required annotation. Through the errors I have the path to the validation rule. Is there any way to get the validation rule through code?
Current workaround is:
Typings (using generic-type-guard)
function isMapConstructorMap(obj: unknown): obj is Map<string, Map<string, string>> {
return (
obj instanceof Map && ((obj.size >= 1 && [...obj.values()].every((x) => x instanceof Map)) || obj.size === 0)
);
}
const isKernelRegel = new IsInterface()
.withProperties({ _additionalKeyValues: isMapConstructorMap, _fehlercode: isString })
.get();
const isKernelMetaModel = new IsInterface()
.withProperties({ _metaRegeln: new IsInterface().withProperties({ _regeln: isArray(isKernelRegel) }).get() })
.get();
Checking for existing annotation:
assertTrue(isKernelMetaModel(metaModel));
const rulesWithGlobalAnnotations = metaModel._metaRegeln._regeln
.filter(
(x) =>
x._additionalKeyValues.get("Annotation") &&
x._additionalKeyValues.get("Annotation")?.has("globalValidationError")
)
.map((x) => x._fehlercode);
This is not particularily clean but works for our case.