mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
fix(Config Schema): Fix errors normalization with external refs
This commit is contained in:
parent
877cbb3fb8
commit
d171f5476d
@ -8,6 +8,20 @@ const normalizeAjvErrors = require('./normalizeAjvErrors');
|
||||
const FUNCTION_NAME_PATTERN = '^[a-zA-Z0-9-_]+$';
|
||||
const ERROR_PREFIX = 'Configuration error';
|
||||
|
||||
const normalizeSchemaObject = (object, instanceSchema) => {
|
||||
for (const [key, value] of _.entries(object)) {
|
||||
if (!_.isObject(value)) continue;
|
||||
if (!value.$ref) {
|
||||
normalizeSchemaObject(value, instanceSchema);
|
||||
continue;
|
||||
}
|
||||
if (!value.$ref.startsWith('#/definitions/')) {
|
||||
throw new Error(`Unsupported reference ${value.$ref}`);
|
||||
}
|
||||
object[key] = _.get(instanceSchema, value.$ref.slice(2).split('/'));
|
||||
}
|
||||
};
|
||||
|
||||
class ConfigSchemaHandler {
|
||||
constructor(serverless) {
|
||||
this.serverless = serverless;
|
||||
@ -55,7 +69,9 @@ class ConfigSchemaHandler {
|
||||
this.relaxProviderSchema();
|
||||
}
|
||||
|
||||
const ajv = new Ajv({ allErrors: true });
|
||||
const ajv = new Ajv({ allErrors: true, verbose: true });
|
||||
// Workaround https://github.com/ajv-validator/ajv/issues/1255
|
||||
normalizeSchemaObject(this.schema, this.schema);
|
||||
const validate = ajv.compile(this.schema);
|
||||
|
||||
validate(userConfig);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user