{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/zindex-ai/json-schema/zindex-ai-diagram-write-schema.json",
  "title": "DiagramWrite",
  "description": "The write envelope a create and an edit return, kept under 100 tokens.",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/zindex-ai-openapi.json#/components/schemas/DiagramWrite",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "The diagram ID, e.g. dgm_7Q2kD9a1B2c3"
    },
    "key": {
      "type": [
        "string",
        "null"
      ]
    },
    "revision": {
      "type": "integer"
    },
    "hash": {
      "type": "string",
      "description": "sha256: of the RFC 8785 canonical content: the scene as view=dsp and the export return it, without `computed`, the engine's drawing output. The node positions in each node's `layout` are content, so they count."
    },
    "chain": {
      "type": [
        "string",
        "null"
      ],
      "description": "The version's chain hash: sha256: of \"zindex-chain/1\\n\" + the previous kept version's chain hash (empty for the first kept version) + \"\\n\" + this version's content hash + \"\\n\" + its stored image's hash, each as lowercase hex without sha256:. It covers every kept version up to this one. null until Zindex has computed it, normally when the version is saved; a render, an export or the next edit computes a missing one. Reads and the history never compute it. https://zindex.ai/docs/concepts/#verifying"
    },
    "changed": {
      "type": "object",
      "properties": {
        "added": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "updated": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "removed": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "moved": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "more": {
          "type": "integer",
          "description": "How many IDs were left out of the lists"
        }
      },
      "description": "added, updated and removed: the elements the edit added, changed in any way besides their position or size, or removed. moved: those whose only change is their position or size, such as the target of a moveElement or resizeElement and the nodes the engine moved or saved at a new size to make room (https://zindex.ai/docs/reference/layout-engine/#positions-are-kept lists when). A frame that only gained new elements or lost deleted ones is in none of the lists unless its layout changed; then it is moved. At most 20 IDs in all, filled in the order added, updated, removed, moved, so moved is cut first; more counts the rest."
    },
    "warnings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DiagramWarning"
      }
    },
    "created": {
      "type": "boolean",
      "description": "false when a create with the same key and content returned the existing diagram"
    },
    "noop": {
      "type": "boolean",
      "description": "The edit changed nothing; revision is the current one"
    },
    "replayed": {
      "type": "boolean",
      "description": "The requestId matched an earlier edit; this is its result"
    }
  },
  "required": [
    "id",
    "revision",
    "hash",
    "chain",
    "warnings"
  ],
  "$defs": {
    "DiagramWarning": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "description": "The warning's code"
        },
        "element": {
          "type": "string",
          "description": "The element it concerns, when there is one"
        },
        "fix": {
          "type": "string",
          "description": "One line on what to change"
        }
      },
      "required": [
        "code",
        "fix"
      ],
      "description": "A problem that doesn't block a save: a rule of the scene or its diagram family, what laying out and drawing it noticed (TEXT_OVERFLOW, ICON_NOT_FOUND, NODE_OVERLAP_DETECTED, NODE_OUTSIDE_FRAME, FRAME_OVERLAP_DETECTED, NODE_IN_WRONG_FRAME, LABEL_DUPLICATION_DETECTED, EDGE_CROSSES_NODE, SPAN_COVERS_NODE, CHARACTER_NOT_DRAWN), a note from converting Mermaid, a note on a field it dropped from what it was sent (PORTS_REMOVED), or a note on what a deleteElement changed besides the element it named: a constraint it removed (CONSTRAINT_REMOVED), an element placed relative to the deleted one (RELATIVE_LAYOUT_FIXED), a spanning frame it left spanning nothing and removed (SPAN_REMOVED), or a sequence diagram's operand or activation bar it left with nothing and removed (FRAGMENT_OPERAND_REMOVED, ACTIVATION_REMOVED; a move with after or before can remove an operand too). Or a plan limit near at hand (LIMIT_NEAR: fix gives the count, the limit and what stops there). Other changes an edit makes on its own get no note; changed lists every element it added, updated or removed, and every element it only moved or resized. At most 10 per response. Every other code: https://zindex.ai/docs/reference/validation-rules/"
    }
  }
}