Enable $data reference usage for AJV validation
See original GitHub issuePrerequisites
- I have read the documentation;
Description
Looking at the docs for AJV, it enables us to write validation rules using $data
reference to an existing schema field’s value, like
var ajv = new Ajv({$data: true});
var schema = {
"properties": {
"smaller": {
"type": "number",
"maximum": { "$data": "1/larger" }
},
"larger": { "type": "number" }
}
};
var validData = {
smaller: 5,
larger: 7
};
ajv.validate(schema, validData); // true
But the default setup for AJV in RJSF does not enable $data=true
Is this an opinionated design choice for some reason or we can somehow enable it. I couldn’t find documentation that lets us override the AJV setup.
Having the $data
reference will enable us to write more complex schema based validations.
Is this something you will be open to enabling or letting users override this option somehow?
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Modifying data during validation - Ajv JSON schema validator
Ajv has several options that allow to modify data during validation: removeAdditional - to remove properties not defined in the schema object. useDefaults...
Read more >Ajv options - Ajv JSON schema validator
Defines how date-time strings are parsed and validated. By default Ajv only allows full date-time strings, as required by JTD specification. Use allowDate:...
Read more >Combining schemas - Ajv JSON schema validator
You can structure your validation logic across multiple schema files and have schemas reference each other using $ref keyword. Example:.
Read more >API Reference | Ajv JSON schema validator
Validate data using passed schema (it will be compiled and cached). Instead of the schema you can use the key that was previously...
Read more >Frequently Asked Questions - Ajv JSON schema validator
"properties" keyword does not require the presence of any properties, you need to use "required" keyword. It also doesn't require that the data...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually, given that $data is not yet part of the JSON Schema spec (it’s just a proposal as of now – see https://github.com/json-schema-org/json-schema-spec/issues/51), it might be better to wait until we see if and/or how it is incorporated into the JSON schema spec before implementing it in rjsf.
Hey, I’ve created a fix for this waiting to be approved by the team: https://github.com/rjsf-team/react-jsonschema-form/pull/1668