Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket event schema #8218

Merged
merged 14 commits into from Sep 18, 2020
Merged
61 changes: 59 additions & 2 deletions lib/plugins/aws/package/compile/events/websockets/index.js
Expand Up @@ -12,6 +12,9 @@ const compileDeployment = require('./lib/deployment');
const compileStage = require('./lib/stage');
const compileAuthorizers = require('./lib/authorizers');

const standardRoutes = new Set(['connect', 'disconnect', 'default']);
const routePattern = new RegExp(`^(?:[^$].*|\\$(${Array.from(standardRoutes).join('|')}))$`, 'i');
rzaldana marked this conversation as resolved.
Show resolved Hide resolved

class AwsCompileWebsockets {
constructor(serverless, options) {
this.serverless = serverless;
Expand Down Expand Up @@ -51,9 +54,63 @@ class AwsCompileWebsockets {
},
};

// TODO: Complete schema, see https://github.com/serverless/serverless/issues/8019
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'websocket', {
anyOf: [{ type: 'string' }, { type: 'object' }],
anyOf: [
{ type: 'string', regexp: routePattern.toString() },
{
type: 'object',
if: {
properties: {
route: { type: 'string', regexp: /\$connect/.toString() },
},
},
then: {
rzaldana marked this conversation as resolved.
Show resolved Hide resolved
properties: {
route: { type: 'string' },
routeResponseSelectionExpression: {
type: 'string',
regexp: /^(?:\$default)$/.toString(),
},
authorizer: {
anyOf: [
{ type: 'string' },
{
type: 'object',
properties: {
name: { type: 'string' },
identitySource: { type: 'array', items: { type: 'string' } },
},
required: ['name'],
additionalProperties: false,
},
{
type: 'object',
properties: {
arn: { type: 'string' },
identitySource: { type: 'array', items: { type: 'string' } },
},
required: ['arn'],
additionalProperties: false,
},
],
},
},
required: ['route'],
additionalProperties: false,
},
else: {
properties: {
route: { type: 'string', regexp: routePattern.toString() },
routeResponseSelectionExpression: {
type: 'string',
regexp: /^(?:\$default)$/.toString(),
},
},
required: ['route'],
additionalProperties: false,
},
},
],
});
}
}
Expand Down
15 changes: 15 additions & 0 deletions lib/plugins/aws/provider/awsProvider.js
Expand Up @@ -236,6 +236,7 @@ class AwsProvider {
},
provider: {
properties: {
// httpApi properties
httpApi: {
type: 'object',
properties: {
Expand Down Expand Up @@ -313,6 +314,17 @@ class AwsProvider {
},
],
},
websocket: {
oneOf: [
{ type: 'boolean' },
{
type: 'object',
properties: {
level: { type: 'string', regexp: /^(?:(INFO|ERROR))$/.toString() },
rzaldana marked this conversation as resolved.
Show resolved Hide resolved
},
},
rzaldana marked this conversation as resolved.
Show resolved Hide resolved
],
},
},
},
resourcePolicy: {
Expand All @@ -321,6 +333,9 @@ class AwsProvider {
type: 'object',
},
},
// websockets properties
websocketsApiName: { type: 'string' },
websocketsApiRouteSelectionExpression: { type: 'string' },
medikoo marked this conversation as resolved.
Show resolved Hide resolved
},
},
function: {
Expand Down