A ref to a root $id that is only a fragment fails in the ata validator
Detect
- In your schema, a root whose
$idis only a fragment that does not start with a letter, or that holds a character other than a letter, a digit,_,.,:or-, such as{ $id: '#1' },{ $id: '#_x' }or{ $id: '#a b' }, and a$refto that fragment, such as{ $ref: '#1' }. A$refto a pointer such as#/xalready failed. - Validation fails with
cannot resolve $ref #1on the field holding the$refwhen the form's data has a value there.
Change
@rjsf/validator-ata now needs ata-validator 1.66.1. JSON Schema allows no fragment in an $id from 2019-09 on, and 1 is not a valid anchor name, so $ref: '#1' names no schema. isValid() already read it that way. With ata-validator before 1.66.0, validateFormData() checked the data at the $ref against the root one level down and accepted anything below that, so { n: { n: { a: 5 } } } passed a root whose a must be a string. ata-validator 1.66.0 reads the $ref as naming nothing, so data reaching it fails with cannot resolve $ref #1. A root $id that is an anchor, such as #root, still names the root.
A precompiled validator still reads $ref: '#1' as the root and checks the data against it, so it accepts data the runtime validator now rejects.
Refer to the root with $ref: '#', or give the root a full $id and refer to that:
const schema = {
$id: '#1',
type: 'object',
- properties: { a: { type: 'string' }, n: { $ref: '#1' } },
+ properties: { a: { type: 'string' }, n: { $ref: '#' } },
};
Verify
- Validation reports no
cannot resolve $referror, and reports the errors of the data at every level below the$ref. - The runtime and precompiled validators agree on the form's data.