Skip to content

Commit

Permalink
Factorize destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbarthelet committed Sep 8, 2020
1 parent 26da5e8 commit 0eaa004
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 61 deletions.
6 changes: 5 additions & 1 deletion lib/classes/ConfigSchemaHandler/index.js
Expand Up @@ -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 };
Expand Down Expand Up @@ -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[
Expand Down
94 changes: 34 additions & 60 deletions lib/plugins/aws/package/compile/events/stream/index.js
Expand Up @@ -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' },
Expand All @@ -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'],
Expand All @@ -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'],
Expand Down

0 comments on commit 0eaa004

Please sign in to comment.