Skip to content

Commit a52b93b

Browse files
authored
Merge pull request #98 from tomharvey/request-mapping-templates-dynamodb
feat(dynamodb): custom request mapping templates
2 parents 2a832aa + 40b471d commit a52b93b

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

.travis.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ language: node_js
33
matrix:
44
include:
55
- node_js: '8.9'
6-
- node_js: '10.6'
76
env:
8-
- INTEGRATION_TESTS=true
7+
- DISABLE_INTEGRATION_TESTS=true
8+
- node_js: '10.6'
99
- node_js: '10.6'
1010
env:
11-
- DISABLE_TESTS=true
11+
- DISABLE_INTEGRATION_TESTS=true
12+
- DISABLE_UNIT_TESTS=true
1213
- LINTING=true
1314

1415
sudo: false
@@ -17,9 +18,9 @@ install:
1718
- travis_retry npm install
1819

1920
script:
20-
- if [[ -z "$DISABLE_TESTS" ]]; then npm run test; fi
21-
- if [[ ! -z "$DISABLE_TESTS" && ! -z "$LINTING" ]]; then npm run lint; fi
22-
- if [[ ! -z "$INTEGRATION_TESTS" && $TRAVIS_BRANCH == "master" && $TRAVIS_PULL_REQUEST == "false" ]]; then npm run integration-test; fi
21+
- if [[ -z "$DISABLE_UNIT_TESTS" ]]; then npm run test; fi
22+
- if [[ ! -z "$LINTING" ]]; then npm run lint; fi
23+
- if [[ -z "$DISABLE_INTEGRATION_TESTS" ]]; then npm run integration-test; fi
2324

2425
after_success:
25-
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
26+
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage

lib/apiGateway/schema.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ const proxiesSchemas = {
288288
tableName: stringOrRef.required(),
289289
condition: Joi.string(),
290290
hashKey: dynamodbDefaultKeyScheme.required(),
291-
rangeKey: dynamodbDefaultKeyScheme
291+
rangeKey: dynamodbDefaultKeyScheme,
292+
request
292293
})
293294
}),
294295
eventbridge: Joi.object({

lib/apiGateway/validate.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,5 +2190,24 @@ describe('#validateServiceProxies()', () => {
21902190

21912191
expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.not.throw()
21922192
})
2193+
2194+
it('should not throw error if request is a mapping template object', () => {
2195+
serverlessApigatewayServiceProxy.serverless.service.custom = {
2196+
apiGatewayServiceProxies: [
2197+
{
2198+
dynamodb: {
2199+
tableName: 'yourTable',
2200+
path: 'dynamodb',
2201+
method: 'put',
2202+
action: 'PutItem',
2203+
hashKey: { pathParam: 'id', attributeType: 'S' },
2204+
request: { template: { 'application/json': 'mapping template' } }
2205+
}
2206+
}
2207+
]
2208+
}
2209+
2210+
expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.not.throw()
2211+
})
21932212
})
21942213
})

lib/package/dynamodb/compileMethodsToDynamodb.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,30 @@ describe('#compileMethodsToDynamodb()', () => {
393393
{}
394394
)
395395
})
396+
397+
it('should create a custom request template when one is given', () => {
398+
const customRequestTemplate = "#set($inputRoot = $input.path('$'))\n{ }"
399+
testPutItem(
400+
{
401+
hashKey: { pathParam: 'id', attributeType: 'S' },
402+
rangeKey: { pathParam: 'range', attributeType: 'S' },
403+
path: '/dynamodb/{id}/{range}',
404+
condition: 'attribute_not_exists(id)',
405+
action: 'PutItem',
406+
request: {
407+
template: {
408+
'application/json': customRequestTemplate,
409+
'application/x-www-form-urlencoded': customRequestTemplate
410+
}
411+
}
412+
},
413+
{
414+
'application/json': customRequestTemplate,
415+
'application/x-www-form-urlencoded': customRequestTemplate
416+
},
417+
{}
418+
)
419+
})
396420
})
397421

398422
describe('#get method', () => {

0 commit comments

Comments
 (0)