mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-14 22:05:01 +00:00
Run a loose pre-check before preprocessStaticConfig
This loose pre-check checks the config schema by treating every object as partial. This means that if a property exists, it's guaranteed to be the correct type (e.g. object). However, there's no guarantee that all or any properties exist. This allows preprocessStaticConfig implementations to be much less defensive and thus reduce boilerplate.
This commit is contained in:
parent
279a8fe7ae
commit
ba2873a29a
4 changed files with 124 additions and 1 deletions
|
@ -83,6 +83,17 @@ const report = fold((errors: any): StrictValidationError | void => {
|
|||
return new StrictValidationError(errorStrings);
|
||||
}, noop);
|
||||
|
||||
export function validate(schema: t.Type<any>, value: any): StrictValidationError | null {
|
||||
const validationResult = schema.decode(value);
|
||||
return pipe(
|
||||
validationResult,
|
||||
fold(
|
||||
err => report(validationResult),
|
||||
result => null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes and validates the given value against the given schema while also disallowing extra properties
|
||||
* See: https://github.com/gcanti/io-ts/issues/322
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue