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 apiGateway event - make sure http request parameters have boolean value #8329
aws apiGateway event - make sure http request parameters have boolean value #8329
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8329 +/- ##
=======================================
Coverage 88.01% 88.01%
=======================================
Files 249 249
Lines 9307 9307
=======================================
Hits 8192 8192
Misses 1115 1115
Continue to review full report at Codecov.
|
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.
Thank you @thewizarodofoz ! Please see my comment
@@ -14,7 +14,7 @@ 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] = _.isObject(value) ? value.required || false : value; |
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.
I think intention was to make it required by default when object form is used. So I believe it should be:
_.isObject(value)
? ((value.required != null) ? value.required : true)
: value
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.
Thank you @thewizarodofoz ! We're near there. There are just some convention issues, please see my comment
@@ -14,7 +14,13 @@ 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; | |||
/* eslint-disable no-nested-ternary */ |
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 not disable lint. Technically this rule is turned on, on purpose, so code style like that is not introduced :)
I know I've written comment abusing that rule, but it was just for quick reference.
We can write it differently, probably with IIFE:
requestParameters[key] = (() => {
if (!_.isObject(value)) return value;
return value.required != null ? value.required : true
})();
@@ -603,6 +603,35 @@ describe('#compileMethods()', () => { | |||
}); | |||
}); | |||
|
|||
it('should set required to true when omitted from mapped value', () => { | |||
awsCompileApigEvents.validated.events = [ |
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.
All new tests should be introduced with runServerless
util, see https://github.com/serverless/serverless/tree/master/test#unit-tests
Relying on mocked awsCompileApigEvents
and other classes like that, is very painful for eventual future refactors
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.
Thank you @thewizarodofoz ! Looks great!
No description provided.