-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
ADD z-schema validator plugin #1157
Conversation
@pubkey I took the same tests as the ajv-validator plugin, does that makes sense to you? |
src/plugins/validate-z-schema.js
Outdated
* @ | ||
*/ | ||
function _getValidator() { | ||
const schemaPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; |
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.
Is there a reason why you do not use javascript-defaults like here?
@phil-lgr thank you for that great PR. |
there is a couple of issues: In my app I get:
|
de9af96
to
d3a9471
Compare
const validatorsOfHash = validatorsCache[hash]; | ||
|
||
if (!validatorsOfHash[schemaPath]) { | ||
const schemaPart = schemaPath === '' ? rxSchema.jsonID : rxSchema.getSchemaByObjectPath(schemaPath); |
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 understand where does the getSchemaByObjectPath
comes from? @pubkey mmmm
Ok so I'm working on this again now |
d3a9471
to
3479066
Compare
|
||
const runAfterSchemaCreated = rxSchema => { | ||
// pre-generate the validator-z-schema from the schema | ||
requestIdleCallbackIfAvailable(() => _getValidator.bind(rxSchema, rxSchema)); |
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 not sure why but I had to .bind here... otherwise the test would work, but in the browser it wouldn't.. if you have a better way to handle this let me know
@@ -94,7 +94,8 @@ | |||
"spark-md5": "^3.0.0", | |||
"unload": "2.1.0", | |||
"url": "^0.11.0", | |||
"util": "^0.12.0" | |||
"util": "^0.12.0", | |||
"z-schema": "^4.0.2" |
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 noticed that 'ajv' is not listed here, are users supposed to install themselves? if so I guess I should remove z-schema from here
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 ajv is missing. Z-schema schould stay there. Im offline since monday btw, i can help then.
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 version of ajv should I add?
What is the state of this? |
I've been using my fork for sometime, it works fine! Not sure what we need to add to the PR, if you can review the code style comments above that would be great |
This PR contains:
Describe the problem you have without this PR
Both
is-my-json-valid
andajv-validate
useeval()
to perform validation which might not be wanted when'unsafe-eval'
is not allowed in Content Security Policies. This one is using z-schema as validator which doesn't useeval
.Todos
Related to #243, actually closes #235