-
Notifications
You must be signed in to change notification settings - Fork 22
Conversation
afce9a6
to
f8a47c2
Compare
856a83a
to
272a691
Compare
272a691
to
d7495f0
Compare
Updated TuplesDuring various validation phases we often push parsing/other errors to the gavel.js/lib/api/units/validateBody.js Line 45 in d7495f0
gavel.js/lib/api/units/validateBody.js Lines 186 to 197 in d7495f0
Parsed body media typeThe main algorithmic difference introduced is the storage of body type as a parsed media type: gavel.js/lib/api/units/validateBody.js Lines 64 to 73 in d7495f0
This way we can get a relevant body validator based on already parsed body media type (previously we would have to parse body content type again): gavel.js/lib/api/units/validateBody.js Lines 138 to 154 in d7495f0
Please, @honzajavorek, I would like to ask you to review |
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.
My main concern would be I didn't find enough evidence to support the case for tuples instead of exceptions.
Also we should go by trial & error and find out what the current behavior is regarding content types. I assembled a table according to my own assumptions, but it is incorrect according to how Gavel currently works. We should find out and test it and document it, perhaps even before reimplementing it.
8630403
to
8e1e045
Compare
1ea72cf
to
56444c3
Compare
I see the PR description mentions it fixes an issue, but none of the 30 commits has a |
@@ -6,6 +6,7 @@ module.exports = { | |||
node: true | |||
}, | |||
rules: { | |||
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], |
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.
Why is this added? I don't see anything with leading underscores.
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.
It's used here currently:
gavel.js/lib/api/units/validateBody.js
Line 140 in e260a4c
const validator = validators.find(([_name, predicate]) => { |
We can always swap the order of arguments, but it feels as a wrong compromise imho. The order of arguments if a functional design decision, and alerts on unused variables is a developer-friendly reminder. I would prioritize the first one, but am always open to discussion :)
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'm fine with it, but perhaps it doesn't deserve a global rule if it's at a single place :)
}); | ||
|
||
describe('given non-json headers', () => { | ||
const res = validateHeaders( |
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.
Nitpick: res
can sometimes mean response (often within express.js), here it's result
. May be worth having the full word here, but it's a very minor thing, leaving up to you.
ddf4aed
to
f42f615
Compare
97b95a4
to
20ec986
Compare
🎉 This PR is included in version 3.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
These changes are meant to modularize the logic in Gavel and replace classes architecture by functions and functional composition.
GitHub
Roadmap
isValid(out of scope)isValidatable(out of scope)Discoveries
TextDiff
as a fallback body validator in case no matching validator is foundgetBodyType
and similar utils to prevent deep testing hierarchy. Assert validity of the validation response onvalidateBody
, assert validity of real/expected body types in the respective utility unit tests. (8630403)validateBody
that need access to other fields of req/res (i.e.headers
). It appears that normalization of transaction elements must happen before each individual validation unit is executed, meaning before invokingvalidateReq
/validateRes
.headers
normalization. Ensure it's an Object, fallback to empty Object if it's not set, and throw exception if it's rubbish (aef5079)error
arguments to thecallback
ofvalidate
(8ae92b4)getBodyType
error on non-parsable JSON to be different for real/expected content types (e8a6406)validate
(dc8a743)