question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable $data reference usage for AJV validation

See original GitHub issue

Prerequisites

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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
epicfaacecommented, Dec 9, 2019

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.

0reactions
zeddotescommented, Mar 21, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found