Skip to content

Commit

Permalink
Merge pull request #64 from jurriaanpro/add-config-validation
Browse files Browse the repository at this point in the history
Add configuration validation
  • Loading branch information
jthomerson committed Mar 22, 2021
2 parents faf72d8 + b170078 commit 6fe9d14
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/index.js
Expand Up @@ -16,6 +16,43 @@ module.exports = Class.extend({
throw new Error('This plugin must be used with AWS');
}

serverless.configSchemaHandler.defineCustomProperties({
type: 'object',
properties: {
'lambdaAtEdge': {
type: 'object',
properties: {
retain: { type: 'boolean' },
},
},
},
});

const functionPropertySchema = {
type: 'object',
properties: {
distribution: { type: 'string' },
eventType: { enum: VALID_EVENT_TYPES },
pathPattern: { type: 'string' },
},
required: [ 'distribution', 'eventType' ],
};

serverless.configSchemaHandler.defineFunctionProperties('aws', {
properties: {
'lambdaAtEdge': {
oneOf: [
{
type: 'array',
items: functionPropertySchema,
},
functionPropertySchema,
],
},
},
required: [ 'lambdaAtEdge' ],
});

this.hooks = {
'aws:package:finalize:mergeCustomProviderResources': this._modifyTemplate.bind(this),
};
Expand Down
4 changes: 4 additions & 0 deletions src/tests/index.test.js
Expand Up @@ -15,6 +15,10 @@ function stubServerless() {
consoleLog: _.noop,
printDot: _.noop,
},
configSchemaHandler: {
defineCustomProperties: _.noop,
defineFunctionProperties: _.noop,
},
};
}

Expand Down

0 comments on commit 6fe9d14

Please sign in to comment.