Skip to content

Commit a50c2a7

Browse files
author
Jeremiah Langner
committed
feat(dynamodb): add request parameters to db requests
1 parent 31cf96d commit a50c2a7

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

lib/apiGateway/schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ const proxiesSchemas = {
300300
condition: Joi.string(),
301301
hashKey: dynamodbDefaultKeyScheme.required(),
302302
rangeKey: dynamodbDefaultKeyScheme,
303+
requestParameters,
303304
request,
304305
response: extendedResponse
305306
})

lib/package/dynamodb/compileMethodsToDynamodb.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
Type: 'AWS::ApiGateway::Method',
1515
Properties: {
1616
HttpMethod: event.http.method.toUpperCase(),
17-
RequestParameters: {},
17+
RequestParameters: event.http.acceptParameters || {},
1818
AuthorizationType: event.http.auth.authorizationType,
1919
AuthorizationScopes: event.http.auth.authorizationScopes,
2020
AuthorizerId: event.http.auth.authorizerId,
@@ -58,6 +58,7 @@ module.exports = {
5858
]
5959
},
6060
PassthroughBehavior: 'NEVER',
61+
RequestParameters: this.getDynamodbIntegrationRequestParameters(http),
6162
RequestTemplates: this.getDynamodbIntegrationRequestTemplates(http)
6263
}
6364

@@ -144,6 +145,15 @@ module.exports = {
144145
}
145146
},
146147

148+
getDynamodbIntegrationRequestParameters(http) {
149+
const defaultRequestParameters = this.buildDefaultDynamodbRequestParameters(http)
150+
return Object.assign(defaultRequestParameters, _.get(http, ['request', 'requestParameters']))
151+
},
152+
153+
buildDefaultDynamodbRequestParameters(http) {
154+
return _.merge({}, http.requestParameters)
155+
},
156+
147157
getDynamodbObjectHashkeyParameter(http) {
148158
if (http.hashKey.pathParam) {
149159
return {

lib/package/dynamodb/compileMethodsToDynamodb.test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ describe('#compileMethodsToDynamodb()', () => {
8484
})
8585

8686
const testSingleProxy = (opts) => {
87-
const { http, logicalId, method, intRequestTemplates, uri, intResponseTemplates } = opts
87+
const {
88+
http,
89+
logicalId,
90+
method,
91+
requestParams,
92+
intRequestTemplates,
93+
uri,
94+
intResponseTemplates
95+
} = opts
8896

8997
serverlessApigatewayServiceProxy.validated = {
9098
events: [
@@ -112,6 +120,7 @@ describe('#compileMethodsToDynamodb()', () => {
112120
AuthorizerId: http.auth.authorizerId,
113121
Integration: {
114122
Uri: uri,
123+
RequestParameters: requestParams,
115124
RequestTemplates: intRequestTemplates,
116125
IntegrationResponses: [
117126
{
@@ -158,7 +167,7 @@ describe('#compileMethodsToDynamodb()', () => {
158167
logicalId: `ApiGatewayMethoddynamodb${http.method.substring(0, 1).toUpperCase() +
159168
http.method.substring(1)}`,
160169
method: http.method.toUpperCase(),
161-
requestParams,
170+
requestParams: params.RequestParameters || requestParams,
162171
intRequestTemplates,
163172
uri,
164173
intResponseTemplates
@@ -786,6 +795,7 @@ describe('#compileMethodsToDynamodb()', () => {
786795
]
787796
},
788797
PassthroughBehavior: 'NEVER',
798+
RequestParameters: {},
789799
RequestTemplates: {
790800
'application/json': {
791801
'Fn::Sub': [
@@ -902,6 +912,7 @@ describe('#compileMethodsToDynamodb()', () => {
902912
]
903913
},
904914
PassthroughBehavior: 'NEVER',
915+
RequestParameters: {},
905916
RequestTemplates: {
906917
'application/json': {
907918
'Fn::Sub': [

0 commit comments

Comments
 (0)