mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Fix API config validation not taking default options into account
This commit is contained in:
parent
a3f423a1d6
commit
a2d5bb51a7
3 changed files with 8 additions and 4 deletions
|
@ -76,12 +76,14 @@ export function initGuildsAPI(app: express.Express) {
|
|||
parsedConfig = {};
|
||||
}
|
||||
|
||||
const errors = validateGuildConfig(parsedConfig);
|
||||
const errors = await validateGuildConfig(parsedConfig);
|
||||
|
||||
if (errors) {
|
||||
return res.status(422).json({ errors });
|
||||
}
|
||||
|
||||
await configs.saveNewRevision(`guild-${req.params.guildId}`, config, req.user.userId);
|
||||
|
||||
ok(res);
|
||||
});
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { guildPlugins } from "./plugins/availablePlugins";
|
|||
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
|
||||
import { ZeppelinPlugin } from "./plugins/ZeppelinPlugin";
|
||||
import { IZeppelinGuildConfig } from "./types";
|
||||
import { PluginOptions } from "knub";
|
||||
import { configUtils, PluginOptions } from "knub";
|
||||
|
||||
const pluginNameToPlugin = new Map<string, ZeppelinPlugin>();
|
||||
for (const plugin of guildPlugins) {
|
||||
|
@ -26,7 +26,7 @@ const globalConfigRootSchema = t.type({
|
|||
|
||||
const partialMegaTest = t.partial({ name: t.string });
|
||||
|
||||
export function validateGuildConfig(config: any): string[] | null {
|
||||
export async function validateGuildConfig(config: any): Promise<string[] | null> {
|
||||
const validationResult = decodeAndValidateStrict(partialGuildConfigRootSchema, config);
|
||||
if (validationResult instanceof StrictValidationError) return validationResult.getErrors();
|
||||
|
||||
|
@ -40,7 +40,8 @@ export function validateGuildConfig(config: any): string[] | null {
|
|||
|
||||
const plugin = pluginNameToPlugin.get(pluginName);
|
||||
try {
|
||||
plugin.configPreprocessor(pluginOptions as PluginOptions<any>);
|
||||
const mergedOptions = configUtils.mergeConfig(plugin.defaultOptions || {}, pluginOptions);
|
||||
await plugin.configPreprocessor(mergedOptions as PluginOptions<any>);
|
||||
} catch (err) {
|
||||
if (err instanceof StrictValidationError) {
|
||||
return err.getErrors().map(err => {
|
||||
|
|
|
@ -40,6 +40,7 @@ export function getPluginConfigPreprocessor(
|
|||
? decodeAndValidateStrict(blueprint.configSchema, options.config)
|
||||
: options.config;
|
||||
if (decodedConfig instanceof StrictValidationError) {
|
||||
console.log("o", options);
|
||||
throw decodedConfig;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue