From 0eaa004f7fff50e63cfd3eeaaf8c9ccb1e3f9da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barthelet?= Date: Tue, 8 Sep 2020 13:52:23 +0200 Subject: [PATCH] Factorize destinations --- lib/classes/ConfigSchemaHandler/index.js | 6 +- .../package/compile/events/stream/index.js | 94 +++++++------------ 2 files changed, 39 insertions(+), 61 deletions(-) diff --git a/lib/classes/ConfigSchemaHandler/index.js b/lib/classes/ConfigSchemaHandler/index.js index 08f5b975ee43..8dffeda5fd09 100644 --- a/lib/classes/ConfigSchemaHandler/index.js +++ b/lib/classes/ConfigSchemaHandler/index.js @@ -151,7 +151,7 @@ class ConfigSchemaHandler { } if (options.definitions) { - Object.assign(this.schema.definitions, options.definitions); + this.addDefinitionsToSchema(options.definitions); } this.schema.properties.provider.properties.name = { const: name }; @@ -209,6 +209,10 @@ class ConfigSchemaHandler { }); } + addDefinitionsToSchema(definitions) { + Object.assign(this.schema.definitions, definitions); + } + relaxProviderSchema() { this.schema.properties.provider.additionalProperties = true; this.schema.properties.functions.patternProperties[ diff --git a/lib/plugins/aws/package/compile/events/stream/index.js b/lib/plugins/aws/package/compile/events/stream/index.js index 91850f153b7b..f87f9fec63f6 100644 --- a/lib/plugins/aws/package/compile/events/stream/index.js +++ b/lib/plugins/aws/package/compile/events/stream/index.js @@ -11,6 +11,38 @@ class AwsCompileStreamEvents { 'package:compileEvents': this.compileStreamEvents.bind(this), }; + this.serverless.configSchemaHandler.addDefinitionsToSchema({ + streamDestinations: { + type: 'object', + properties: { + onFailure: { + anyOf: [ + { $ref: '#/definitions/awsArnString' }, + { + type: 'object', + properties: { + arn: { $ref: '#/definitions/awsArnString' }, + type: { enum: ['sns', 'sqs'] }, + }, + additionalProperties: false, + required: ['arn'], + }, + { + type: 'object', + properties: { + arn: { $ref: '#/definitions/awsCfFunction' }, + type: { enum: ['sns', 'sqs'] }, + }, + additionalProperties: false, + required: ['arn', 'type'], + }, + ], + }, + }, + additionalProperties: false, + required: ['onFailure'], + }, + }); this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'stream', { anyOf: [ { $ref: '#/definitions/awsArnString' }, @@ -33,36 +65,7 @@ class AwsCompileStreamEvents { { type: 'integer', minimum: 60, maximum: 604800 }, ], }, - destinations: { - type: 'object', - properties: { - onFailure: { - anyOf: [ - { $ref: '#/definitions/awsArnString' }, - { - type: 'object', - properties: { - arn: { $ref: '#/definitions/awsArnString' }, - type: { enum: ['sns', 'sqs'] }, - }, - additionalProperties: false, - required: ['arn'], - }, - { - type: 'object', - properties: { - arn: { $ref: '#/definitions/awsCfFunction' }, - type: { enum: ['sns', 'sqs'] }, - }, - additionalProperties: false, - required: ['arn', 'type'], - }, - ], - }, - }, - additionalProperties: false, - required: ['onFailure'], - }, + destinations: { $ref: '#/definitions/streamDestinations' }, }, additionalProperties: false, required: ['arn'], @@ -86,36 +89,7 @@ class AwsCompileStreamEvents { { type: 'integer', minimum: 60, maximum: 604800 }, ], }, - destinations: { - type: 'object', - properties: { - onFailure: { - anyOf: [ - { $ref: '#/definitions/awsArnString' }, - { - type: 'object', - properties: { - arn: { $ref: '#/definitions/awsArnString' }, - type: { enum: ['sns', 'sqs'] }, - }, - additionalProperties: false, - required: ['arn'], - }, - { - type: 'object', - properties: { - arn: { $ref: '#/definitions/awsCfFunction' }, - type: { enum: ['sns', 'sqs'] }, - }, - additionalProperties: false, - required: ['arn', 'type'], - }, - ], - }, - }, - additionalProperties: false, - required: ['onFailure'], - }, + destinations: { $ref: '#/definitions/streamDestinations' }, }, additionalProperties: false, required: ['arn', 'type'],