mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-18 15:45:03 +00:00
Switch from ajv to io-ts for config validation; validate configs on save in the API/dashboard; start work on creating io-ts schemas for all plugins
This commit is contained in:
parent
1ecce52973
commit
3f4724b699
14 changed files with 256 additions and 41 deletions
27
src/validatorUtils.ts
Normal file
27
src/validatorUtils.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import * as t from "io-ts";
|
||||
import { pipe } from "fp-ts/lib/pipeable";
|
||||
import { fold } from "fp-ts/lib/Either";
|
||||
import { PathReporter } from "io-ts/lib/PathReporter";
|
||||
|
||||
/**
|
||||
* Validates the given value against the given schema while also disallowing extra properties
|
||||
* See: https://github.com/gcanti/io-ts/issues/322
|
||||
*/
|
||||
export function validateStrict(schema: t.Type<any, any, any>, value: any): string[] | null {
|
||||
const validationResult = schema.decode(value);
|
||||
return pipe(
|
||||
validationResult,
|
||||
fold(
|
||||
err => PathReporter.report(validationResult),
|
||||
result => {
|
||||
// Make sure there are no extra properties
|
||||
if (JSON.stringify(value) !== JSON.stringify(result)) {
|
||||
// TODO: Actually mention what the unknown property is
|
||||
return ["Found unknown properties"];
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue