-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Injection of custom ajv instance via prop (+ removal of global ajv) #1286
Conversation
… as default by MultiSchemaField.js)
… utility functions
Hi. Would it be possible with this to add the "verbose" keyword to the ajv instance so I can have more detailed error objects like the Or is this already possible but I am not aware of it...? |
@Gurkenschreck you can pass in any ajv instance, customized to your needs. react-jsonschema-form internally then uses this instance for its validations, but the validations results are processed internally first: take a look at the Unfortunately, IMO the original validation error should be added to each error, similar to #1140 but not just some keys. For example: // put data in expected format
return {
name: keyword,
property,
message,
params, // specific to ajv
stack: `${property} ${message}`.trim(),
+ _ajvError: e,
}; Currently no time for such a pull request. |
@sbusch that's a good idea, can you make an issue for that? |
Maybe if someone (maybe even me) changes it he can consider: {
"type": "string",
"title": "form.questionA.title"
} The error then says e.g. ".a.b[4].c is a required property". Which is not very nice for the user so in the |
Any updates on this PR? Something like this would be really helpful for us since we have some forms where we have multiple fields that require comparisons. For example Even though I could write multiple |
@ankurkaushal I wanted to wait for some feedback from maintainers if my approach is mergeable in principle before I proceed (rebasing it onto newer commits, ...) @epicfaace and other maintainers, whats your opinion? @ankurkaushal You could try to build from my PR and try to implement your stuff using it, could be valuable feedback. I'm sure that removal of global ajv singleton is a necessary step for the project, but when and how is the decision of the maintainers... |
I am not familiar with the code myself (will probably have to sit down on a weekend & go through the code) so it would take me long time implement that myself & we are kind of in a time crunch so it makes things complicated too. But yeah removal of global |
Ping also @edi9999 |
@sbusch I really like this approach, especially how it will simplify and allow for more flexibility than Question -- why is |
It seems to be a great improvement to me ! |
bump :) |
I also like this approach, wish this can be merged soon. |
I'm sorry but I am currently working on other stuff and have no time for the required changes, especially checking & modifying all upstream changes (for new parameter holding the ajv instance) will take some time. If we had 100% test coverage, we could just merge and fix until all is green again, but I think that's not the case?! And advice? |
It would help to see which tests exactly are failing. Do you know why travis isn't running on this PR? |
what can I do to help? I really need this feature. 4 month passed, still no progress. |
@videni would you like to take over this PR and get all the tests to pass? That would help a lot |
If TypeScript migration (#583, with #1446) is also a goal for v2, I propose to hold this PR off until that is finished: Having typings in place - in conjunction with the tests - will help a lot when manually re-applying this PR (which is IMO necessary because of the conflicting nature of this PR vs. many upstream changes). Additionally, the upgrade to React 16 (merged in #1408 ) will also simplify this PR, when my context workarounds can be removed. @epicfaace have you decided on the React version? (#1275) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you. |
Reasons for making this change
DO NOT MERGE YET.
A custom ajv instance can be created and injected to the Form as "ajv" prop. This allows further customizations of behavior.
Notes:
createAjvInstance()
fromutils.js
can be used to generate a preconfigured instance, which can be further customized (by adding custom keywords, ....).customFormats
additionalMetaSchemas
andcustomFormats
)This feature allows to deprecate some features, for example Form features
additionalMetaSchemas
andcustomFormats
could be achieved by an customized ajv, further simplifyingreact-jsonschema-form
implementation.I decided to release this now to get some early feedback. ajv injection and removal of global ajv is finished and tests are passing (see status, below).
I'll try to rebase this for some time on master, but since there are many changes quick feedback would be great...
Comments very appreciated!
Status:
additionalMetaSchemas
andcustomFormats
(deprecation marker in source, updated docs)Checklist
TODO
npm run cs-format
on my branch to conform my code to prettier coding style