mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-14 21:31:50 +00:00
Fix unknown property validation; fix override validation; be clear about which property is unknown
This commit is contained in:
parent
6f75185e74
commit
00e34b322d
5 changed files with 14 additions and 6 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -3853,6 +3853,11 @@
|
|||
"integrity": "sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw=",
|
||||
"dev": true
|
||||
},
|
||||
"deep-diff": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/deep-diff/-/deep-diff-1.0.2.tgz",
|
||||
"integrity": "sha512-aWS3UIVH+NPGCD1kki+DCU9Dua032iSsO43LqQpcs4R3+dVv7tX0qBGjiVHJHjplsoUM2XRO/KB92glqc68awg=="
|
||||
},
|
||||
"deep-extend": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"cross-env": "^5.2.0",
|
||||
"deep-diff": "^1.0.2",
|
||||
"dotenv": "^4.0.0",
|
||||
"emoji-regex": "^8.0.0",
|
||||
"eris": "^0.10.1",
|
||||
|
|
|
@ -18,7 +18,7 @@ const guildConfigRootSchema = t.type({
|
|||
levels: t.record(t.string, t.number),
|
||||
plugins: t.record(t.string, t.unknown),
|
||||
});
|
||||
const partialGuildConfigRootSchema = t.exact(t.partial(guildConfigRootSchema.props));
|
||||
const partialGuildConfigRootSchema = t.partial(guildConfigRootSchema.props);
|
||||
|
||||
const globalConfigRootSchema = t.type({
|
||||
url: t.string,
|
||||
|
|
|
@ -63,7 +63,7 @@ export class ZeppelinPlugin<TConfig extends {} = IBasePluginConfig> extends Plug
|
|||
{},
|
||||
(this.getStaticDefaultOptions() as any).config || {},
|
||||
options.config || {},
|
||||
...options.overrides.slice(0, i),
|
||||
...options.overrides.slice(0, i).map(o => o.config || {}),
|
||||
override.config,
|
||||
);
|
||||
const errors = validateStrict(this.configSchema, merged);
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as t from "io-ts";
|
|||
import { pipe } from "fp-ts/lib/pipeable";
|
||||
import { fold } from "fp-ts/lib/Either";
|
||||
import { noop } from "./utils";
|
||||
import deepDiff from "deep-diff";
|
||||
|
||||
// From io-ts/lib/PathReporter
|
||||
function stringify(v) {
|
||||
|
@ -42,8 +43,8 @@ const report = fold((errors: any) => {
|
|||
* 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);
|
||||
export function validateStrict(schema: t.HasProps, value: any): string[] | null {
|
||||
const validationResult = t.exact(schema).decode(value);
|
||||
return pipe(
|
||||
validationResult,
|
||||
fold(
|
||||
|
@ -51,8 +52,9 @@ export function validateStrict(schema: t.Type<any, any, any>, value: any): strin
|
|||
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"];
|
||||
const diff = deepDiff(result, value);
|
||||
const errors = diff.filter(d => d.kind === "N").map(d => `Unknown property <${d.path.join(".")}>`);
|
||||
return errors.length ? errors : ["Found unknown properties"];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Add table
Reference in a new issue