{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openappdefinition.org/schema/0.2/design.schema.json",
  "title": "OAD 0.2 design system",
  "description": "A design system (*.oaddesign.json): a separately versioned document that supplies tokens, variants, custom control catalogs and agent conventions. Definitions refer to tokens and variants by name only.",
  "type": "object",
  "required": ["oadDesign", "id", "version", "meta", "tokens"],
  "properties": {
    "$schema": {
      "description": "Optional URI of a JSON Schema for this document, for editors. Hosts ignore it.",
      "$ref": "common.schema.json#/$defs/uriReference"
    },
    "oadDesign": {
      "title": "version marker",
      "description": "Spec version the design system targets, MAJOR.MINOR. This schema validates version 0.2.",
      "$ref": "common.schema.json#/$defs/specVersion",
      "const": "0.2"
    },
    "id": {
      "description": "Globally unique identifier in reverse-DNS form.",
      "$ref": "common.schema.json#/$defs/reverseDnsId"
    },
    "version": {
      "description": "Semantic version of the design system.",
      "$ref": "common.schema.json#/$defs/semver"
    },
    "meta": {
      "description": "Descriptive information about the design system.",
      "$ref": "#/$defs/meta"
    },
    "tokens": {
      "description": "Named values grouped by token group. Required, with the minimum color and space tokens every design system defines.",
      "$ref": "#/$defs/tokens"
    },
    "modes": {
      "description": "Optional mode name (such as dark or highContrast) to a partial tokens object that overrides the base tokens while that mode is active.",
      "type": "object",
      "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
      "additionalProperties": { "$ref": "#/$defs/partialTokens" }
    },
    "variants": {
      "description": "Maps a fully qualified control (catalogId:contractName) to named prop presets. A node selects one with the common variant prop.",
      "type": "object",
      "propertyNames": { "$ref": "common.schema.json#/$defs/qualifiedContractRef" },
      "additionalProperties": { "$ref": "#/$defs/variantSet" }
    },
    "catalogs": {
      "description": "Catalogs of custom controls that belong to the design system.",
      "type": "array",
      "items": { "$ref": "common.schema.json#/$defs/versionedReference" }
    },
    "agent": {
      "description": "Conventions for agent surfaces generated under this design system.",
      "$ref": "#/$defs/agentConventions"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "meta": {
      "title": "design meta",
      "description": "Descriptive information about the design system.",
      "type": "object",
      "required": ["name", "description"],
      "properties": {
        "name": {
          "description": "Human-readable name of the design system.",
          "$ref": "common.schema.json#/$defs/text"
        },
        "description": {
          "description": "Plain-language description of the design system.",
          "$ref": "common.schema.json#/$defs/text"
        },
        "publisher": {
          "description": "Who publishes the design system.",
          "$ref": "common.schema.json#/$defs/text"
        },
        "license": {
          "description": "License of the design system, as an SPDX expression.",
          "$ref": "common.schema.json#/$defs/text"
        }
      },
      "additionalProperties": false
    },
    "tokens": {
      "title": "tokens",
      "description": "Token groups. The group names in 0.2 are color, space, type, radius, motion and shadow. color and space are required and define a common minimum.",
      "type": "object",
      "properties": {
        "color": {
          "description": "Named colors, including the required minimum set.",
          "$ref": "#/$defs/baseColors"
        },
        "space": {
          "description": "Named spacing sizes, including small, medium and large.",
          "$ref": "#/$defs/baseSpace"
        },
        "type": {
          "description": "Named type styles.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/typeStyle" }
        },
        "radius": {
          "description": "Named corner radii.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/size" }
        },
        "motion": {
          "description": "Named motion durations.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/motionValue" }
        },
        "shadow": {
          "description": "Levels of shadow a canvas draws under a shape, by name: low, medium and high. A design that names none has the default design system's.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/shadowStyle" }
        }
      },
      "additionalProperties": false,
      "required": ["color", "space"]
    },
    "partialTokens": {
      "title": "partial tokens",
      "description": "Token groups that override some base tokens. Nothing is required.",
      "type": "object",
      "properties": {
        "color": {
          "description": "Named colors.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/colorValue" }
        },
        "space": {
          "description": "Named spacing sizes.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/size" }
        },
        "type": {
          "description": "Named type styles.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/typeStyle" }
        },
        "radius": {
          "description": "Named corner radii.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/size" }
        },
        "motion": {
          "description": "Named motion durations.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/motionValue" }
        },
        "shadow": {
          "description": "Levels of shadow a canvas draws under a shape, by name: low, medium and high. A design that names none has the default design system's.",
          "type": "object",
          "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
          "additionalProperties": { "$ref": "#/$defs/shadowStyle" }
        }
      },
      "additionalProperties": false
    },
    "baseColors": {
      "title": "base colors",
      "description": "Named colors. Every design system defines surface, text, textMuted, outline, accent, onAccent, the tones neutral, info, success, warning and danger, and category1 to category8 for data series.",
      "type": "object",
      "required": ["surface", "text", "textMuted", "outline", "accent", "onAccent", "neutral", "info", "success", "warning", "danger", "category1", "category2", "category3", "category4", "category5", "category6", "category7", "category8"],
      "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
      "properties": {
        "surface": {
          "description": "Background of the app and its containers.",
          "$ref": "#/$defs/colorValue"
        },
        "text": {
          "description": "Primary text and icons on surface.",
          "$ref": "#/$defs/colorValue"
        },
        "textMuted": {
          "description": "Secondary text on surface.",
          "$ref": "#/$defs/colorValue"
        },
        "outline": {
          "description": "Borders and dividers.",
          "$ref": "#/$defs/colorValue"
        },
        "accent": {
          "description": "Emphasis and primary actions.",
          "$ref": "#/$defs/colorValue"
        },
        "onAccent": {
          "description": "Text and icons drawn on accent.",
          "$ref": "#/$defs/colorValue"
        },
        "neutral": {
          "description": "Neutral tone.",
          "$ref": "#/$defs/colorValue"
        },
        "info": {
          "description": "Informational tone.",
          "$ref": "#/$defs/colorValue"
        },
        "success": {
          "description": "Success tone.",
          "$ref": "#/$defs/colorValue"
        },
        "warning": {
          "description": "Warning tone.",
          "$ref": "#/$defs/colorValue"
        },
        "danger": {
          "description": "Danger tone.",
          "$ref": "#/$defs/colorValue"
        },
        "category1": {
          "description": "Data series color 1.",
          "$ref": "#/$defs/colorValue"
        },
        "category2": {
          "description": "Data series color 2.",
          "$ref": "#/$defs/colorValue"
        },
        "category3": {
          "description": "Data series color 3.",
          "$ref": "#/$defs/colorValue"
        },
        "category4": {
          "description": "Data series color 4.",
          "$ref": "#/$defs/colorValue"
        },
        "category5": {
          "description": "Data series color 5.",
          "$ref": "#/$defs/colorValue"
        },
        "category6": {
          "description": "Data series color 6.",
          "$ref": "#/$defs/colorValue"
        },
        "category7": {
          "description": "Data series color 7.",
          "$ref": "#/$defs/colorValue"
        },
        "category8": {
          "description": "Data series color 8.",
          "$ref": "#/$defs/colorValue"
        }
      },
      "additionalProperties": { "$ref": "#/$defs/colorValue" }
    },
    "baseSpace": {
      "title": "base space",
      "description": "Named spacing sizes. Every design system defines small, medium and large.",
      "type": "object",
      "required": ["small", "medium", "large"],
      "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
      "properties": {
        "small": {
          "description": "Small spacing.",
          "$ref": "#/$defs/size"
        },
        "medium": {
          "description": "Medium spacing.",
          "$ref": "#/$defs/size"
        },
        "large": {
          "description": "Large spacing.",
          "$ref": "#/$defs/size"
        }
      },
      "additionalProperties": { "$ref": "#/$defs/size" }
    },
    "colorValue": {
      "title": "color",
      "description": "A color written #rrggbb or #rrggbbaa in hexadecimal.",
      "type": "string",
      "pattern": "^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$"
    },
    "size": {
      "title": "size",
      "description": "A non-negative size in density-independent units (one unit is a CSS pixel at standard density).",
      "type": "number",
      "minimum": 0
    },
    "motionValue": {
      "title": "motion duration",
      "description": "A duration in milliseconds.",
      "type": "number",
      "minimum": 0
    },
    "shadowStyle": {
      "title": "shadow",
      "description": "A level of shadow: how far down it falls and how soft it is, in density-independent units, and how opaque it is at its darkest. Its color is the design's ink.",
      "type": "object",
      "required": ["offset", "blur", "opacity"],
      "properties": {
        "offset": { "description": "How far down the shadow falls.", "$ref": "#/$defs/size" },
        "blur": { "description": "How soft its edge is: the blur radius, as a CSS box shadow's.", "$ref": "#/$defs/size" },
        "opacity": { "description": "How opaque the shadow is at its darkest, from 0 to 1.", "type": "number", "minimum": 0, "maximum": 1 }
      },
      "additionalProperties": false
    },
    "typeStyle": {
      "title": "type style",
      "description": "A type style: font family, size and weight, with optional lineHeight.",
      "type": "object",
      "required": ["family", "size", "weight"],
      "properties": {
        "family": {
          "description": "A font family name, or one of the generic names system-ui, serif, sans-serif and monospace.",
          "$ref": "common.schema.json#/$defs/text"
        },
        "size": {
          "description": "Font size, in the same units as space.",
          "type": "number",
          "exclusiveMinimum": 0
        },
        "weight": {
          "description": "Font weight, from 1 to 1000.",
          "type": "integer",
          "minimum": 1,
          "maximum": 1000
        },
        "lineHeight": {
          "description": "Optional line height, as a multiple of size.",
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "additionalProperties": false
    },
    "variantSet": {
      "title": "variant set",
      "description": "Named prop presets for one control.",
      "type": "object",
      "propertyNames": { "$ref": "common.schema.json#/$defs/name" },
      "additionalProperties": { "$ref": "#/$defs/variantPreset" }
    },
    "variantPreset": {
      "title": "variant preset",
      "description": "Prop name to literal value. Presets may set only props the contract declares.",
      "type": "object",
      "propertyNames": { "$ref": "common.schema.json#/$defs/name" }
    },
    "agentConventions": {
      "title": "agent conventions",
      "description": "Naming and error-message conventions for agent surfaces.",
      "type": "object",
      "properties": {
        "toolNaming": {
          "description": "Naming convention for tools, such as camelCase.",
          "$ref": "common.schema.json#/$defs/text"
        },
        "errorStyle": {
          "description": "How error messages should be written for agents.",
          "$ref": "common.schema.json#/$defs/text"
        }
      },
      "additionalProperties": false
    }
  }
}
