Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(AWS API Gateway): Fix resolution of request parameters required v…
…alue

(PR #8329)
  • Loading branch information
Oz Weiss committed Oct 6, 2020
1 parent e753399 commit d2fb696
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Expand Up @@ -14,7 +14,10 @@ module.exports = {
const requestParameters = {};
if (event.http.request && event.http.request.parameters) {
Object.entries(event.http.request.parameters).forEach(([key, value]) => {
requestParameters[key] = value.required === undefined ? value : value.required;
requestParameters[key] = (() => {
if (!_.isObject(value)) return value;
return value.required != null ? value.required : true;
})();
});
}

Expand Down
Expand Up @@ -4,6 +4,7 @@ const expect = require('chai').expect;
const AwsCompileApigEvents = require('../../index');
const Serverless = require('../../../../../../../../Serverless');
const AwsProvider = require('../../../../../../provider/awsProvider');
const runServerless = require('../../../../../../../../../test/utils/run-serverless');

describe('#compileMethods()', () => {
let serverless;
Expand Down Expand Up @@ -603,6 +604,43 @@ describe('#compileMethods()', () => {
});
});

it('should set required to true when omitted from mapped value', async () => {
const { cfTemplate } = await runServerless({
cliArgs: ['package'],
fixture: 'function',
configExt: {
functions: {
foo: {
events: [
{
http: {
path: 'users/create',
method: 'post',
integration: 'HTTP_PROXY',
request: {
uri: 'https://example.com',
parameters: {
querystrings: {
foo: {
mappedValue: 'bar',
},
},
},
},
},
},
],
},
},
},
});
expect(
cfTemplate.Resources.ApiGatewayMethodUsersCreatePost.Properties.RequestParameters[
'method.request.querystring.foo'
]
).to.equal(true);
});

it('should set authorizer config for AWS_IAM', () => {
awsCompileApigEvents.validated.events = [
{
Expand Down

0 comments on commit d2fb696

Please sign in to comment.