Merge pull request #5610 from brethubbard/master
Improve error messages when schema validation fails
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/catalog-model': patch
|
||||
---
|
||||
|
||||
Improve error messages when schema validation fails
|
||||
@@ -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