Improve error messages when schema validation fails
Signed-off-by: Bret Hubbard <hubbard.bret@gmail.com>
This commit is contained in:
@@ -168,4 +168,16 @@ components:
|
||||
(entity as any).spec.system = '';
|
||||
await expect(validator.check(entity)).rejects.toThrow(/system/);
|
||||
});
|
||||
|
||||
it('rejects additional properties', async () => {
|
||||
(entity as any).annotations = 'Test';
|
||||
await expect(validator.check(entity)).rejects.toThrow(
|
||||
/additional properties/,
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects with useful error message', async () => {
|
||||
(entity as any).annotations = 'Test';
|
||||
await expect(validator.check(entity)).rejects.toThrow(/annotations/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,7 +66,13 @@ export function ajvCompiledJsonSchemaValidator(
|
||||
}
|
||||
|
||||
throw new TypeError(
|
||||
`Malformed ${kind}, ${error.dataPath || '<root>'} ${error.message}`,
|
||||
`Malformed ${kind}, ${error.dataPath || '<root>'} ${error.message}${
|
||||
error.params
|
||||
? ` - ${Object.entries(error.params)
|
||||
.map(([key, val]) => `${key}: ${val}`)
|
||||
.join(', ')}`
|
||||
: ''
|
||||
}`,
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user