export function formatError(error) {
    let pathStr = error.instancePath;
    let message = error.message ?? '';
    if ('missingProperty' in error.params) {
        pathStr = `${pathStr}.${error.params.missingProperty}`;
    }
    if ('additionalProperty' in error.params) {
        pathStr = `${pathStr}.${error.params.additionalProperty}`;
        message = `${message} "${error.params.additionalProperty}"`;
    }
    if ('allowedValues' in error.params) {
        message = `${message} "${error.params.allowedValues.join('", "')}"`;
    }
    const path = pathStr === '' ? [] : pathStr.substr(1).split(/\.|\/|\['|']\./);
    return {
        type: 'json',
        message,
        path
    };
}
