diff --git a/package-lock.json b/package-lock.json index 10a0e24..b92e761 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "serverless-api-gateway-caching", - "version": "1.5.0", + "version": "1.5.2-rc1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index de9bf2c..7ff7434 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-api-gateway-caching", - "version": "1.5.1", + "version": "1.5.2", "description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.", "main": "src/apiGatewayCachingPlugin.js", "scripts": { diff --git a/src/apiGatewayCachingPlugin.js b/src/apiGatewayCachingPlugin.js index 80bcd5c..7b6e99c 100644 --- a/src/apiGatewayCachingPlugin.js +++ b/src/apiGatewayCachingPlugin.js @@ -15,6 +15,8 @@ class ApiGatewayCachingPlugin { 'before:package:finalize': this.updateCloudFormationTemplate.bind(this), 'after:aws:deploy:finalize:cleanup': this.updateStage.bind(this), }; + + this.defineValidationSchema(serverless); } createSettings() { @@ -51,6 +53,78 @@ class ApiGatewayCachingPlugin { return updateStageCacheSettings(this.settings, this.serverless); } + + defineValidationSchema() { + if (!this.serverless.configSchemaHandler + || !this.serverless.configSchemaHandler.defineCustomProperties + || !this.serverless.configSchemaHandler.defineFunctionEventProperties) { + return; + } + + const customSchema = this.customCachingSchema(); + this.serverless.configSchemaHandler.defineCustomProperties(customSchema); + + const httpSchema = this.httpEventCachingSchema(); + this.serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'http', httpSchema); + } + + httpEventCachingSchema() { + return { + type: 'object', + properties: { + caching: { + properties: { + enabled: { type: 'boolean' }, + ttlInSeconds: { type: 'number' }, + dataEncrypted: { type: 'boolean' }, + perKeyInvalidation: { + properties: { + requireAuthorization: { type: 'boolean' }, + handleUnauthorizedRequests: { + type: 'string', + enum: ['Ignore', 'IgnoreWithWarning', 'Fail'] + } + } + }, + cacheKeyParameters: { + type: 'array', + items: { + properties: { + name: { type: 'string' }, + value: { type: 'string' } + } + } + } + } + } + } + } + } + + customCachingSchema() { + return { + type: 'object', + properties: { + apiGatewayCaching: { + properties: { + enabled: { type: 'boolean' }, + clusterSize: { type: 'string' }, + ttlInSeconds: { type: 'number' }, + dataEncrypted: { type: 'boolean' }, + perKeyInvalidation: { + properties: { + requireAuthorization: { type: 'boolean' }, + handleUnauthorizedRequests: { + type: 'string', + enum: ['Ignore', 'IgnoreWithWarning', 'Fail'] + } + } + } + } + } + } + } + } } module.exports = ApiGatewayCachingPlugin;