A ref that names nothing fails validation in the ata validator
Detect
- In your schema or in an
additionalMetaSchemasorataOptionsOverrides.schemasentry: a$refthat names nothing, such as one to a definition the document lacks, or, in an entry, one naming a document by URI, such asurn:y#/definitions/noneor a relativenone.json, where the document or the pointer is missing. - An error
cannot resolve $reffollowed by the$refon the root, with no other errors, when the$refsits undernot, anif, aoneOfbranch, acontainswithmaxContains, or a schema withunevaluatedPropertiesorunevaluatedItems. - The same error on the field, with the other errors of the form, when the
$refis in an entry, names a document by URI, and sits under none of those, such as an entry reached through a property's$ref. - A precompiled validator throws
was not compiled to a standalone validatorwhen the form validates against such a schema.
Change
@rjsf/validator-ata now needs ata-validator 1.66.1, where 6.x took any version from 1.56.0, so a 6.x install could already resolve 1.66.0, where this changed. A $ref that names nothing has no answer, and earlier versions failed only the subschema holding it. Under not, an if, a oneOf branch, or a contains with maxContains and minContains: 0, that failure could turn into a pass, so { not: { $ref: '#/definitions/none' } } accepted every value. In an extra schema, a $ref naming a document by URI that finds nothing there accepted every value too, whether it names a document that is not registered, another entry, or the entry's own $id, such as urn:x#/definitions/none in the entry urn:x. A $ref that is a # pointer alone, such as #/definitions/none, already failed the field.
Data that reaches such a $ref now fails validation, in one of two ways:
- Under
not, anif, aoneOfbranch, acontainswithmaxContains, or a schema withunevaluatedPropertiesorunevaluatedItems, the whole validation fails with the one errorcannot resolve $ref #/definitions/noneon the root, and no other errors are reported. This holds for a$refin your schema and in an extra schema. Undernot, anif, aoneOfbranch, or acontainswithmaxContainsandminContains: 0, the data used to pass. Under the others it already failed, with the error on the item or the field and the form's other errors beside it. - Anywhere else in an extra schema, such as one reached through a property's
$ref, a$refnaming a document by URI fails the field holding it with that error, and the form's other errors are reported as usual.
A form whose data does not reach the $ref validates as before. An anyOf branch holding such a $ref is still skipped silently while another branch matches, so with the runtime validator { anyOf: [{ $ref: '#/definitions/none' }, { type: 'string' }] } accepts 'x' with no error, as before. compileSchemaValidatorsCode() compiles no function for such a schema, so a precompiled validator throws was not compiled to a standalone validator, as it already did for a $ref that names nothing in the root.
Point each such $ref at a schema, register the document it names, or remove it:
const schema = {
- properties: { name: { type: 'string', not: { $ref: '#/definitions/reserved' } } },
+ definitions: { reserved: { enum: ['admin', 'root'] } },
+ properties: { name: { type: 'string', not: { $ref: '#/definitions/reserved' } } },
};
Verify
- Validation reports the errors your data has, and no
cannot resolve $referror. AnanyOfbranch holding a$refthat names nothing reports none while another branch matches, so search your schema for those too. - Errors for other fields show again where a
cannot resolve $referror on the root hid them. - A regenerated precompiled validator validates the form without
was not compiled to a standalone validator.