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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
add async validation support #4762
Conversation
} catch (error) { | ||
expect(error.message).to.equal(INVALID_MSG); | ||
expect(error.code).to.equal('VALIDATION_FAILED'); | ||
} |
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.
We use await expect(aPromise).to.be.rejectedWith(...)
style.
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.
Done!
let validationResult = validate(body); | ||
let validationErrors: AJV.ErrorObject[] = []; | ||
try { | ||
validationResult = await validationResult; |
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 not very friendly to change the type of validationResult
in the same function.
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.
Thanks for pointing it out. I've simplified the logic. Is new one better & clear?
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.
Please squash the commits into one.
Uh oh! I messed it up it seems. Edit 1: Apologies for messing up. I will try to fix it with a hard reset. If it doesn't work, I will send another PR. Edit 2: It seems to have been done properly now. Please help check if it's done right. |
f023e0c
to
25965ba
Compare
@mastermunj Don't worry if you make mistakes with Git, we've all been there. There are plenty of very helpful people who can help you fix what seems like a disaster. It's source control... most problems can be fixed. |
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 @mastermunj for the PR 鉂わ笍
I've added a comment regarding the drop in test coverage and how we might be able to resolve it.
As what @dougal83 mentioned: No worries, if there's any git-related issue, we can help.
If things goes south, there's probably no need to create a new PR. At most a hard-reset against origin/master
will bring things back on track.
// When schema is not available, ajv returns null | ||
if (validationResult || validationResult === null) { | ||
debug('Request body passed AJV validation.'); | ||
return; | ||
} |
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.
Seems like this branch isn't fully covered with tests yet (hence the reduced test coverage).
Is there a case where the schema isn't available when AJV is called?
It'll be great if we can add a test case to prevent regression.
Here's the Coveralls report
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.
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.
@achrinza did you get a chance to look into this?
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.
@mastermunj I would suggest editing the comment to be more accurate to the purpose of the conditional statement.
Though @raymondfeng has approved the PR and this issue is a non-blocker for me.
So everything LGTM 馃憤
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 comment there seems misleading with
schema is not available
. Schema is available but body is optional and value is empty.
I would really like the commit to be updated before this pull request is landed, to avoid confusion in the future.
25965ba
to
8a0d955
Compare
@mastermunj I suggest you further refine the commit message as follows:
|
8a0d955
to
5c63168
Compare
@raymondfeng modified commit message as per your suggestion. |
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.
This is awesome, I really like how the pull request is focused on one thing only (enabling async validations) 馃憤
Let's fix the misleading commit please, before we proceed to land the pull request.
// When schema is not available, ajv returns null | ||
if (validationResult || validationResult === null) { | ||
debug('Request body passed AJV validation.'); | ||
return; | ||
} |
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 comment there seems misleading with
schema is not available
. Schema is available but body is optional and value is empty.
I would really like the commit to be updated before this pull request is landed, to avoid confusion in the future.
BREAKING CHANGE: `validateRequestBody` is now an async function to allow asynchronous validations by custom Ajv keywords and formats. See https://ajv.js.org/#asynchronous-validation for more details.
02da30e
to
3b49284
Compare
@slnode test please |
Add support for async validations. The need arises from allowing custom formats & keywords for ajv, which can also be async in nature.
Checklist
馃憠 Read and sign the CLA (Contributor License Agreement) 馃憟
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated馃憠 Check out how to submit a PR 馃憟