Data Schema

The Data Schema (ip.schema.data_schema field on ip.schema) is a pure JSON Schema draft-07 document. It is used only for payload validation at the network edge — it has no knowledge of Odoo fields. It validates both inbound payloads before import and outbound payloads before delivery. Both schemas are validated at save time by ip.schema._check_schemas(), which raises a ValidationError for invalid field paths, operators, or JSON Schema syntax.

See also


Root Type

The type keyword at the root of the ip.schema.data_schema dictates how Odoo handles the payload:

Value

Behaviour

"object"

One JSON object per event. On export, ensure_one() is called on the recordset — a schema error is raised if more than one record matches.

"array"

A batch of records per event. On export, the entire recordset is serialised into a JSON array in a single event.


Keywords

Keyword

Purpose

Recommendation

$schema

Declares the vocabulary version.

Always include (http://json-schema.org/draft-07/schema#).

type

"object" or "array" at root.

Required.

required

Array of keys that must be present.

List all non-optional fields.

additionalProperties

Controls unknown keys. false rejects them; true ignores them.

Use false — prevents junk ingestion and accidental data leaks.

properties

Named field definitions with type constraints.

Declare every field you map in the Odoo Schema.

patternProperties

Regex-keyed definitions, e.g. "^.*_cid$".

Useful for dynamically-named CID fields.


Example

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["json_ref"],
  "additionalProperties": false,
  "properties": {
    "json_ref": { "type": "string" },
    "content": {
      "type": "object",
      "properties": { "body": { "type": ["string", "null"] } }
    },
    "avatar": {
      "type": "object",
      "properties": {
        "cid_str": { "type": "string" },
        "name":    { "type": "string" }
      }
    },
    "json_tags": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": { "label": { "type": "string" } },
        "required": ["label"]
      }
    }
  }
}

Matching payload:

{
  "json_ref": "REC-001",
  "content":  { "body": "Hello world" },
  "avatar":   { "cid_str": "QmXxxx...", "name": "Profile" },
  "json_tags": [
    { "label": "welcome" },
    { "label": "general" }
  ]
}