-
Notifications
You must be signed in to change notification settings - Fork 22
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
#3059: switch RJSF validator to cfworker/jsonschema #7081
Conversation
…feature/3059-rjsf-cfworker
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #7081 +/- ##
==========================================
+ Coverage 71.14% 71.18% +0.03%
==========================================
Files 1213 1214 +1
Lines 37613 37687 +74
Branches 7075 7088 +13
==========================================
+ Hits 26760 26826 +66
- Misses 10853 10861 +8 ☔ View full report in Codecov by Sentry. |
// Deep clone the schema because otherwise the schema is not extensible | ||
// This breaks validation when @cfworker/json-schema dereferences the schema | ||
// See https://github.com/cfworker/cfworker/blob/263260ea661b6f8388116db7b8daa859e0d28b25/packages/json-schema/src/dereference.ts#L115 | ||
schema={cloneDeep(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.
👍 Does the cloned schema need to be memoized?
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 started off doing that, but I haven't had any issues with performance or mounting/unmounting. I know with formik
and react-hook-form
, the component won't remount/reset unless the key changes. I think we have the same situation 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.
Would like to see some cleanup of the comments in the isValid
function, do we need to make further changes in this PR? Are the comments needed for the future? Just seems a bit uncertain what's going on there, when reading the code/comments from an outside perspective.
src/validators/formValidator.ts
Outdated
// XXX: technically we may want to read from $schema to determine which draft version to validate against | ||
// Draft 7 is the default for RJSF: https://rjsf-team.github.io/react-jsonschema-form/docs/usage/validation/#custom-meta-schema-validation | ||
|
||
if (!this.isValidSchema(schema)) { | ||
return false; | ||
} | ||
|
||
// FIXME: figure out how to add the root schema to the validator | ||
const validator = new Validator( | ||
withIdRefPrefix(schema) as Schema, | ||
// The default used by RJSF: https://rjsf-team.github.io/react-jsonschema-form/docs/usage/validation/#custom-meta-schema-validation | ||
"7", | ||
true, | ||
); | ||
// This breaks due to duplicate ids: validator.addSchema(rootSchema as 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.
Is there anything that needs to be done here with this series of XXX / FIXME / "This breaks"
comments? Do we need to leave all of these in 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.
This one here is the main reason I didn't approve the PR yet, fyi
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.
Good catch - this is a feature that I'm not sure if we need or not, or even what the feature does
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.
At one point I confirmed that this is called, but I'm still unclear what it's doing. Every test case I could come up with is passing. I'll remove the comment.
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
Co-authored-by: Ben Loe <below413@gmail.com>
Co-authored-by: Ben Loe <below413@gmail.com>
No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack. Do not edit this comment manually. |
What does this PR do?
Remaining Work
#/required Instance does not have required property \"pass2\".
.pass2 is a required property
Instance type \"number\" is invalid. Expected \"string\"
Reviewer Tips
Discussion
Demo
Note: Under normal circumstances, the html5 validation will display errors instead of RJSF. I disabled the html5 validation to fallback to the schema validation
Future Work
Checklist
src/tsconfig.strictNullChecks.json
(if possible)