{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openeik.org/schemas/0.3/drawings/derivation.schema.json",
  "$comment": "OpenEik 0.2: folded by tools/fold-schemas.mjs from the proposal drawings, which 0.2 makes a rule (decision D5). Written by hand from the text, not generated.",
  "title": "Derivation",
  "description": "What a revision was drawn from (Part XIV, 6.9): the version, the sheet and views, the generator and its fonts, the read set by hash. An issued drawing.svg holds it in <metadata id=\"openeik-derivation\"> as the text of its canonical JSON (RFC 8785), and the revision record holds the same object as its derivation. It never holds the SVG's digest nor the revision record's. Its hash (Part III, 6) is the derivation's digest.",
  "type": "object",
  "properties": {
    "format": {
      "const": "openeik-drawing-derivation/0.1"
    },
    "drawing": {
      "$ref": "defs.schema.json#/$defs/number"
    },
    "revision": {
      "$ref": "defs.schema.json#/$defs/revisionCode"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "source": {
      "description": "The version drawn from, as Part VI, 8.2's computedFrom names one; root, the model's root tree hash as read (Part VI, 2, rule 4), always given; ref, the line of work the drawing tracks, or null; upstream as Part VI, 8.2.",
      "type": "object",
      "properties": {
        "version": {
          "$ref": "defs.schema.json#/$defs/version"
        },
        "versionKind": {
          "enum": [
            "openeik",
            "git",
            null
          ]
        },
        "root": {
          "$ref": "defs.schema.json#/$defs/hash"
        },
        "ref": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 400
            },
            {
              "type": "null"
            }
          ]
        },
        "upstream": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "properties": {
                "repository": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "ref": {
                  "type": "string",
                  "minLength": 1
                },
                "version": {
                  "$ref": "defs.schema.json#/$defs/commit"
                }
              },
              "required": [
                "repository",
                "ref",
                "version"
              ],
              "x-eik-closed": true
            }
          ]
        }
      },
      "required": [
        "version",
        "versionKind",
        "root",
        "ref",
        "upstream"
      ],
      "allOf": [
        {
          "if": {
            "required": [
              "version"
            ],
            "properties": {
              "version": {
                "type": "null"
              }
            }
          },
          "then": {
            "properties": {
              "versionKind": {
                "const": null
              }
            }
          },
          "else": {
            "properties": {
              "versionKind": {
                "enum": [
                  "openeik",
                  "git"
                ]
              }
            }
          }
        }
      ],
      "x-eik-closed": true
    },
    "sheet": {
      "description": "The sheet record drawn, by its id and its hash.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "defs.schema.json#/$defs/id"
        },
        "hash": {
          "$ref": "defs.schema.json#/$defs/hash"
        }
      },
      "required": [
        "id",
        "hash"
      ],
      "x-eik-closed": true
    },
    "views": {
      "description": "Each placed view's hash with its detail items joined, as the single-file form holds it, by the view's id.",
      "type": "object",
      "propertyNames": {
        "$ref": "defs.schema.json#/$defs/id"
      },
      "additionalProperties": {
        "$ref": "defs.schema.json#/$defs/hash"
      }
    },
    "viewports": {
      "description": "Where each viewport sits on the paper, in the sheet's order.",
      "type": "array",
      "maxItems": 200,
      "items": {
        "$ref": "#/$defs/viewport"
      }
    },
    "generator": {
      "description": "The generator, its version (a release or a commit), the order inside its layers (XIV.6.7), the digest of its style set, and the request it was given.",
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "order": {
          "type": "string",
          "enum": [
            "id",
            "paint"
          ]
        },
        "styles": {
          "$ref": "defs.schema.json#/$defs/hash"
        },
        "request": {
          "type": "object"
        }
      },
      "required": [
        "name",
        "version",
        "order"
      ],
      "x-eik-closed": true
    },
    "fonts": {
      "description": "Each family the file uses, with the SHA-256 of its font file.",
      "type": "object",
      "propertyNames": {
        "type": "string",
        "minLength": 1,
        "maxLength": 120
      },
      "additionalProperties": {
        "$ref": "defs.schema.json#/$defs/hash"
      }
    },
    "readSet": {
      "description": "The read set file's hash (Part III, 6) and its number of distinct pairs.",
      "type": "object",
      "properties": {
        "hash": {
          "$ref": "defs.schema.json#/$defs/hash"
        },
        "count": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "hash",
        "count"
      ],
      "x-eik-closed": true
    },
    "annotations": {
      "description": "How many annotation groups of each origin the file holds.",
      "type": "object",
      "properties": {
        "derived": {
          "type": "integer",
          "minimum": 0
        },
        "person": {
          "type": "integer",
          "minimum": 0
        },
        "agent": {
          "type": "integer",
          "minimum": 0
        }
      },
      "x-eik-closed": true
    }
  },
  "required": [
    "format",
    "drawing",
    "revision",
    "title",
    "source",
    "sheet",
    "views",
    "viewports",
    "generator",
    "fonts",
    "readSet"
  ],
  "x-eik-closed": true,
  "$defs": {
    "viewport": {
      "description": "A viewport: its id, the view placed and the view's kind, its detail number, its place on the paper (mm), its scale (the 75 of 1 : 75), its crop, and the matrix [a, b, c, d, e, f] from view to paper: x = a u + c v + e, y = b u + d v + f. A 3D view's picture has neither scale nor crop: both are null (XIV.6.3; E, item 7).",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "view": {
          "$ref": "defs.schema.json#/$defs/id"
        },
        "kind": {
          "description": "The view's kind (Part II, 10).",
          "type": "string",
          "enum": [
            "plan",
            "section",
            "elevation",
            "3d",
            "drafting"
          ]
        },
        "detailNumber": {
          "type": "string",
          "minLength": 1,
          "maxLength": 40
        },
        "place": {
          "type": "object",
          "properties": {
            "x": {
              "type": "number"
            },
            "y": {
              "type": "number"
            },
            "width": {
              "type": "number",
              "minimum": 0
            },
            "height": {
              "type": "number",
              "minimum": 0
            },
            "rotation": {
              "type": "number",
              "minimum": -360,
              "maximum": 360
            }
          },
          "required": [
            "x",
            "y",
            "width",
            "height",
            "rotation"
          ],
          "x-eik-closed": true
        },
        "scale": {
          "anyOf": [
            {
              "type": "number",
              "exclusiveMinimum": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "crop": {
          "anyOf": [
            {
              "type": "array",
              "minItems": 4,
              "maxItems": 4,
              "items": {
                "type": "number"
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "matrix": {
          "type": "array",
          "minItems": 6,
          "maxItems": 6,
          "items": {
            "type": "number"
          }
        }
      },
      "required": [
        "id",
        "view",
        "kind",
        "detailNumber",
        "place",
        "scale",
        "crop",
        "matrix"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "3d"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "properties": {
              "scale": {
                "type": "null"
              },
              "crop": {
                "type": "null"
              }
            }
          },
          "else": {
            "properties": {
              "scale": {
                "type": "number"
              },
              "crop": {
                "type": "array"
              }
            }
          }
        }
      ],
      "x-eik-closed": true
    }
  }
}
