-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature schema #5
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5 +/- ##
===========================================
- Coverage 100.00% 90.47% -9.53%
===========================================
Files 1 1
Lines 68 42 -26
===========================================
- Hits 68 38 -30
- Misses 0 4 +4
Continue to review full report at Codecov.
|
@lloria91 I'm was expecting to see a test that covers the use case that we started this implementation in the first place 😄 |
Test about Complex case is the test no? Schema is almost same as in worker. |
body: // Joi schema definition | ||
params: // Joi schema definition | ||
headers: // Joi schema definition | ||
schema: // Compiled Joi schema object |
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.
what is the difference between Compiled Joi schema object
and Joi schema
?
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.
if it's the same we should keep the terms
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 have simple JS that is transformed to joi.object. Compiled is already Joi object and don't need to call Joi.object 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.
they call it compilation of JS object to Joi object on their site
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.
So what I want to say there is that if you validate query, params and others separately with old version you need to pass JS object. But for schema need to pass Joi object
src/index.js
Outdated
@@ -94,6 +102,18 @@ export default (inputs) => { | |||
} | |||
|
|||
try { | |||
if (schema) { |
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.
If the schema is true
, are we still checking the others (headers, query ...etc)?
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.
check workers APS-38 MR please. schema contains Joi object. In general its already prepared Joi object and in validator no need to call Joi.object function
README.md
Outdated
- Input validation (`query`, `params`, `body`, `headers`). | ||
- Input validation | ||
- `query`, `params`, `body`, `headers` - each input part is validated separately. | ||
- `schema` - validates all input together, should be used with more complex schemas as [Joi.when](https://hapi.dev/module/joi/api/?v=17.1.1#anywhencondition-options) or [Joi.alternatives](https://hapi.dev/module/joi/api/?v=17.1.1#alternatives). |
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.
- `schema` - validates all input together, should be used with more complex schemas as [Joi.when](https://hapi.dev/module/joi/api/?v=17.1.1#anywhencondition-options) or [Joi.alternatives](https://hapi.dev/module/joi/api/?v=17.1.1#alternatives). | |
- `schema` - validates all input together, should be used with more complex schemas like [Joi.when](https://hapi.dev/module/joi/api/?v=17.1.1#anywhencondition-options) and [Joi.alternatives](https://hapi.dev/module/joi/api/?v=17.1.1#alternatives). |
if (schema) { | ||
await handleErrorWithSource( | ||
"schema", | ||
schema.validateAsync({ |
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 don't really understand how the schema is working, roles. e.g.
Add an example with an explanation in the README.
The worker case is a |
FInally after testing when and alternatives, it is alternative )) |
adding custom schema validation feature
schema should be compiled Joi schema object.