3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-14 22:05:01 +00:00

Validate override criteria and extra criteria. When loading existing configs, silently remove invalid overrides.

This commit is contained in:
Dragory 2021-05-23 18:10:23 +03:00
parent 8ab6538744
commit 52e4b5b519
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 62 additions and 5 deletions

View file

@ -111,7 +111,11 @@ export function validate(schema: t.Type<any>, value: any): StrictValidationError
* Decodes and validates the given value against the given schema while also disallowing extra properties
* See: https://github.com/gcanti/io-ts/issues/322
*/
export function decodeAndValidateStrict<T extends t.HasProps>(schema: T, value: any): StrictValidationError | any {
export function decodeAndValidateStrict<T extends t.HasProps>(
schema: T,
value: any,
debug = false,
): StrictValidationError | any {
const validationResult = t.exact(schema).decode(value);
return pipe(
validationResult,
@ -119,6 +123,14 @@ export function decodeAndValidateStrict<T extends t.HasProps>(schema: T, value:
err => report(validationResult),
result => {
// Make sure there are no extra properties
if (debug)
console.log(
"JSON.stringify() check:",
JSON.stringify(value) === JSON.stringify(result)
? "they are the same, no excess"
: "they are not the same, might have excess",
result,
);
if (JSON.stringify(value) !== JSON.stringify(result)) {
const diff = deepDiff(result, value);
const errors = diff.filter(d => d.kind === "N").map(d => `Unknown property <${d.path.join(".")}>`);