Docs / EventSourcingDB / Errors / event-schema-not-object

event-schema-not-object

A schema does not describe an object at its top level.

  • Routes: register-event-schema and restore-backup
  • Description: event schema does not describe an object: expected type 'object', since the data of an event is always a JSON object
  • Details: When registering a schema, none; details is an empty object. When restoring a backup, part, the part of the backup that holds the schema, counting from 0, with the full backup as part 0, and value, the event type of the schema.

Why It Happens#

The data of an event is always a JSON object, so a schema for it has to say so with "type": "object" at its top level. A schema that leaves out type, such as {}, that names another type, such as "string", or that only refers to a definition with $ref at its top level is refused. The top-level type has to be exactly the string "object", so a list such as ["object"] is refused as well. JSON Schema knows the keyword as type alone, so a member that spells it otherwise, such as Type or TYPE, says nothing about the type: {"TYPE": "object"} is refused as a schema that names no type, and so is {"type": "string", "TYPE": "object"}, which describes a string.

A schema that is not a valid JSON Schema at all is reported as event-schema-malformed instead, since that is checked first. When restoring a backup, every schema of the backup is checked the same way, as it is read, also in a backup that the v1 API created. Restoring such a backup through the v1 API refuses the schema as well, with a 400, see Compatibility.

How to Fix It#

Put "type": "object" at the top level of the schema, also next to a $ref that refers to a definition of the object. Sending the same request again fails the same way, since the error depends on the schema alone.

Example#

To register a schema for io.eventsourcingdb.library.book-acquired that only refers to the definition #/$defs/book with $ref at its top level, EventSourcingDB answers with this error, as a line of the stream, and then ends the stream with its end item:

{
  "type": "error",
  "data": {
    "code": "https://docs.eventsourcingdb.io/errors/event-schema-not-object",
    "description": "event schema does not describe an object: expected type 'object', since the data of an event is always a JSON object",
    "details": {}
  }
}