Fix message validation (#957)

This commit is contained in:
Alexander Krivonosov 2021-10-11 13:33:55 +03:00 committed by GitHub
parent d5289e1d13
commit e8fb5d3241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,14 +8,17 @@ const validateMessage = async (
setSchemaErrors: React.Dispatch<React.SetStateAction<string[]>>
): Promise<boolean> => {
setSchemaErrors([]);
const ajv = new Ajv();
const keyAjv = new Ajv();
const contentAjv = new Ajv();
try {
if (messageSchema) {
let keyIsValid = false;
let contentIsValid = false;
try {
const validateKey = ajv.compile(JSON.parse(messageSchema.key.schema));
const validateKey = keyAjv.compile(
JSON.parse(messageSchema.key.schema)
);
keyIsValid = validateKey(JSON.parse(key));
if (!keyIsValid) {
const errorString: string[] = [];
@ -32,7 +35,7 @@ const validateMessage = async (
setSchemaErrors((e) => [...e, `Key ${err.message}`]);
}
try {
const validateContent = ajv.compile(
const validateContent = contentAjv.compile(
JSON.parse(messageSchema.value.schema)
);
contentIsValid = validateContent(JSON.parse(content));