Skip to main content
Version: Current (v7.0.0-beta.3)

A ref that names nothing fails validation in the ata validator

Detect​

  • In your schema or in an additionalMetaSchemas or ataOptionsOverrides.schemas entry: a $ref that names nothing, such as one to a definition the document lacks, or, in an entry, one naming a document by URI, such as urn:y#/definitions/none or a relative none.json, where the document or the pointer is missing.
  • An error cannot resolve $ref followed by the $ref on the root, with no other errors, when the $ref sits under not, an if, a oneOf branch, a contains with maxContains, or a schema with unevaluatedProperties or unevaluatedItems.
  • The same error on the field, with the other errors of the form, when the $ref is 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 validator when 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, an if, a oneOf branch, a contains with maxContains, or a schema with unevaluatedProperties or unevaluatedItems, the whole validation fails with the one error cannot resolve $ref #/definitions/none on the root, and no other errors are reported. This holds for a $ref in your schema and in an extra schema. Under not, an if, a oneOf branch, or a contains with maxContains and minContains: 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 $ref naming 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 $ref error. An anyOf branch holding a $ref that 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 $ref error on the root hid them.
  • A regenerated precompiled validator validates the form without was not compiled to a standalone validator.