mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-11 13:07:20 +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
b59a957a3d
commit
c10d12ac22
4 changed files with 124 additions and 1 deletions
41
backend/src/validation.test.ts
Normal file
41
backend/src/validation.test.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { tDeepPartial } from "./utils";
|
||||
import * as t from "io-ts";
|
||||
import * as validatorUtils from "./validatorUtils";
|
||||
import test from "ava";
|
||||
import util from "util";
|
||||
|
||||
test("tDeepPartial works", ava => {
|
||||
const originalSchema = t.type({
|
||||
listOfThings: t.record(
|
||||
t.string,
|
||||
t.type({
|
||||
enabled: t.boolean,
|
||||
someValue: t.number,
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
const deepPartialSchema = tDeepPartial(originalSchema);
|
||||
|
||||
const partialValidValue = {
|
||||
listOfThings: {
|
||||
myThing: {
|
||||
someValue: 5,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const partialErrorValue = {
|
||||
listOfThings: {
|
||||
myThing: {
|
||||
someValue: "test",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const result1 = validatorUtils.validate(deepPartialSchema, partialValidValue);
|
||||
ava.is(result1, null);
|
||||
|
||||
const result2 = validatorUtils.validate(deepPartialSchema, partialErrorValue);
|
||||
ava.not(result2, null);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue