-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Aws http event schema #8301
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
Aws http event schema #8301
Changes from all commits
684c3ea
b843b02
b7236f2
af31807
0ea0dc8
276f688
b8e46ad
50fb4c8
e76e4d5
f6c4fd9
f2c1a87
a04fb5d
b9820ad
d8d59cf
7011b4c
71104ac
7bd1098
34c1fe7
0cfae06
c32a320
912ab8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,15 +20,190 @@ const getMethodAuthorization = require('./lib/method/authorization'); | |
| const getMethodIntegration = require('./lib/method/integration'); | ||
| const getMethodResponses = require('./lib/method/responses'); | ||
|
|
||
| function caseInsensitive(str) { | ||
| return { type: 'string', regexp: new RegExp(`^${str}$`, 'i').toString() }; | ||
| } | ||
|
|
||
| const contentHandlingSchema = { enum: ['CONVERT_TO_BINARY', 'CONVERT_TO_TEXT'] }; | ||
|
|
||
| const allowedMethods = ['GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'HEAD', 'DELETE', 'ANY']; | ||
| const methodPattern = new RegExp(`^(?:\\*|${allowedMethods.join('|')})$`, 'i'); | ||
| const methodPathPattern = new RegExp(`^(?:\\*|(${allowedMethods.join('|')}) (\\/\\S*))$`, 'i'); | ||
|
|
||
| const requestParametersSchema = { | ||
| type: 'object', | ||
| additionalProperties: { | ||
| oneOf: [ | ||
| { type: 'boolean' }, | ||
| { | ||
| type: 'object', | ||
| properties: { | ||
| required: { type: 'boolean' }, | ||
| mappedValue: { type: 'string' }, | ||
| }, | ||
| additionalProperties: false, | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| const authorizerSchema = { | ||
| oneOf: [ | ||
| { type: 'string' }, | ||
| caseInsensitive('aws_iam'), | ||
| { $ref: '#/definitions/awsArnString' }, | ||
| { | ||
| type: 'object', | ||
| properties: { | ||
| arn: { $ref: '#/definitions/awsArn' }, | ||
| authorizerId: { $ref: '#/definitions/awsCfInstruction' }, | ||
| claims: { type: 'array', items: { type: 'string' } }, | ||
| identitySource: { type: 'string' }, | ||
| identityValidationExpression: { type: 'string' }, | ||
| managedExternally: { type: 'boolean' }, | ||
| name: { type: 'string' }, | ||
| resultTtlInSeconds: { type: 'integer', minimum: 0, maximum: 3600 }, | ||
| scopes: { type: 'array', items: { type: 'string' } }, | ||
| type: { | ||
| oneOf: ['token', 'cognito_user_pools', 'request', 'aws_iam'].map(caseInsensitive), | ||
| }, | ||
| }, | ||
| required: [], | ||
| additionalProperties: false, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const corsSchema = { | ||
| oneOf: [ | ||
| { type: 'boolean' }, | ||
| { | ||
| type: 'object', | ||
| properties: { | ||
| allowCredentials: { type: 'boolean' }, | ||
| cacheControl: { type: 'string' }, | ||
| headers: { type: 'array', items: { type: 'string' } }, | ||
| maxAge: { type: 'integer', minimum: 1 }, | ||
| methods: { type: 'array', items: { enum: allowedMethods } }, | ||
|
medikoo marked this conversation as resolved.
|
||
| origin: { type: 'string' }, | ||
| origins: { | ||
| type: 'array', | ||
| items: { type: 'string' }, | ||
| }, | ||
| }, | ||
| oneOf: [{ required: ['origin'] }, { required: ['origins'] }], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to also introduce
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me from the code that indeed one of them is required. We also had this manual validation that I removed which supports my theory.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, it appears that if someone uses an object form, then not providing Still that looks as apparent design bug, as by supporting Anyway this is side issue (not a concern of this PR) so yes let's leave it as required. |
||
| additionalProperties: false, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const requestSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| contentHandling: contentHandlingSchema, | ||
| method: { type: 'string', regexp: methodPattern.toString() }, | ||
| parameters: { | ||
| type: 'object', | ||
| properties: { | ||
| querystrings: requestParametersSchema, | ||
| headers: requestParametersSchema, | ||
| paths: requestParametersSchema, | ||
| }, | ||
| additionalProperties: false, | ||
| }, | ||
| passThrough: { enum: ['NEVER', 'WHEN_NO_MATCH', 'WHEN_NO_TEMPLATES'] }, | ||
| schema: { | ||
| type: 'object', | ||
| additionalProperties: { type: 'object' }, | ||
| }, | ||
| template: { | ||
| type: 'object', | ||
| additionalProperties: { type: 'string' }, | ||
| }, | ||
| uri: { type: 'string' }, | ||
| }, | ||
| additionalProperties: false, | ||
| }; | ||
|
|
||
| const responseSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| contentHandling: contentHandlingSchema, | ||
| headers: { | ||
| type: 'object', | ||
| additionalProperties: { type: 'string' }, | ||
| }, | ||
| template: { type: 'string' }, | ||
| statusCodes: { | ||
| type: 'object', | ||
| propertyNames: { | ||
| type: 'string', | ||
| pattern: '^\\d{3}$', | ||
| }, | ||
| additionalProperties: { | ||
|
medikoo marked this conversation as resolved.
|
||
| type: 'object', | ||
| properties: { | ||
| headers: { | ||
| type: 'object', | ||
| additionalProperties: { type: 'string' }, | ||
| }, | ||
| pattern: { type: 'string' }, | ||
| template: { | ||
| oneOf: [ | ||
| { type: 'string' }, | ||
| { | ||
| type: 'object', | ||
| additionalProperties: { type: 'string' }, | ||
| }, | ||
| ], | ||
| }, | ||
|
medikoo marked this conversation as resolved.
|
||
| }, | ||
| additionalProperties: false, | ||
| }, | ||
| }, | ||
| }, | ||
| additionalProperties: false, | ||
| }; | ||
|
|
||
| class AwsCompileApigEvents { | ||
| constructor(serverless, options) { | ||
| this.serverless = serverless; | ||
| this.options = options; | ||
| this.provider = this.serverless.getProvider('aws'); | ||
|
|
||
| this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'http', { | ||
| // TODO: Complete schema, see https://github.com/serverless/serverless/issues/8018 | ||
| anyOf: [{ type: 'string' }, { type: 'object' }], | ||
| anyOf: [ | ||
| { type: 'string', regexp: methodPathPattern.toString() }, | ||
| { | ||
| type: 'object', | ||
| properties: { | ||
| async: { type: 'boolean' }, | ||
| authorizer: authorizerSchema, | ||
| connectionId: { type: 'string' }, | ||
| connectionType: { oneOf: ['vpc-link', 'VPC_LINK'].map(caseInsensitive) }, | ||
| cors: corsSchema, | ||
| integration: { | ||
| oneOf: [ | ||
| 'LAMBDA_PROXY', | ||
| 'LAMBDA', | ||
| 'AWS', | ||
| 'AWS_PROXY', | ||
| 'HTTP', | ||
| 'HTTP_PROXY', | ||
| 'MOCK', | ||
| ].map(caseInsensitive), | ||
| }, | ||
| method: { type: 'string', regexp: methodPattern.toString() }, | ||
| operationId: { type: 'string' }, | ||
| path: { type: 'string', regexp: /^(?:\*|\/?\S*)$/.toString() }, | ||
| private: { type: 'boolean' }, | ||
| request: requestSchema, | ||
| response: responseSchema, | ||
| }, | ||
| required: ['path', 'method'], | ||
| additionalProperties: false, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| // used for the generated method logical ids (GET, PATCH, PUT, DELETE, OPTIONS, ...) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep alphabetical order