Skip to content

Validation

Validation tells you how well your data matches a model, without standing in the way of the people entering it. Findings are recorded, but a failed validation never blocks a write.

Validation schemas

You attach any number of named JSON Schema documents to a type. Drafts 4 to 2020-12 are supported, selected by $schema. Without $schema, 2020-12 is assumed.

Action Request
List GET /v4/types/validationSchemas?type=...
Read GET /v4/types/validationSchemas/{name}?type=...
Create or replace PUT /v4/types/validationSchemas/{name}?type=... with the schema as body
Delete DELETE /v4/types/validationSchemas/{name}?type=...

All of these need DEFINE_VALIDATION_SCHEMAS, which is granted by the ADMIN role.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.org/schemas/person",
  "type": "object",
  "required": ["https://example.org/properties/name"],
  "properties": {
    "https://example.org/properties/name": { "type": "string", "minLength": 1 }
  }
}

Schemas see the instance as GET /v4/instances/{id} returns it: the payload with @id, @type and _space.

Schemas referencing each other

A $ref to another IRI is resolved against the $id of the stored schemas, across all types. Each $id can be used by only one schema. Schemas may be uploaded in any order. Until a referenced schema exists, validating against the one referencing it reports a $ref error. Apart from the bundled meta-schemas, nothing is ever fetched from the network.

Validation on write

Each create and update validates the resulting instance against all schemas of its type and stores the findings next to it, replacing the previous ones. They are available with returnValidationResults.

Pass validate=false to skip the validation of a write, for example during a bulk import. Since the stored findings wouldn't apply to the new state, they are removed.

Check on demand

Check Request Permission
A stored instance GET /v4/instances/{id}/validation?stage=... Read access
A payload for a new instance POST /v4/instances/validation/payload?space=... CREATE and WRITE in the space
A change to an existing instance POST /v4/instances/{id}/validation READ and WRITE

All accept schema=<name> to use just one schema. The two POST variants are dry runs: nothing is stored, so a form can show problems while someone is still typing. partial=true treats the payload like a PATCH. For an existing instance, the payload is merged with other users' contributions, exactly as a real write would be.

Result

{
  "type": "https://example.org/types/Person",
  "valid": false,
  "schemas": [
    {
      "name": "person-basics",
      "valid": false,
      "compliance": 50,
      "errors": [
        {
          "instanceLocation": ["https://example.org/authors", 0, "https://example.org/name"],
          "keyword": "type",
          "message": "..."
        }
      ]
    }
  ]
}

instanceLocation is the path to the problem, with [] meaning the instance itself. An instance whose type has no schema is valid.

Compliance score

compliance estimates how much of the schema is met: the share of the properties declared at the top level of the schema (in properties or required) that have no violations, as a percentage.

  • A missing required property, or an invalid value at any depth, makes that property non-compliant.
  • Violations that can't be attributed to a declared property only affect valid.
  • A schema with no declared properties scores 100 if valid and 0 otherwise.

Validate everything

After changing a schema, you can revalidate existing data:

POST /v4/instances/validation?space=neuroscience

Omit space for all spaces. This replaces the stored findings and returns {instances, validated, failed}. Only one run can be active at a time (409 otherwise). It needs the global functionality VALIDATE_INSTANCES, granted by ADMIN.

The aggregate picture for your data is available through the statistics.