{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Create Custom Attribute",
  "description": "Declare a custom attribute key for your organization. Custom attributes control which user-defined attribute keys can be set on resources at each level of the hierarchy. System attributes (md-*) are auto-injected by Massdriver and do not need to be declared.",
  "type": "object",
  "required": ["key", "scope", "values"],
  "properties": {
    "key": {
      "type": "string",
      "title": "Attribute Key",
      "description": "1-64 characters, identifier-like: starts with a letter or underscore; letters, digits, and underscores only. Case-insensitive (TEAM and team are the same key). Keys starting with md- are reserved for system use.",
      "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$",
      "minLength": 1,
      "maxLength": 64,
      "examples": ["TEAM", "cost_center", "tier1"]
    },
    "scope": {
      "type": "string",
      "x-gql-type": "attribute_scope",
      "title": "Scope",
      "description": "The resource level where this attribute is set. Hierarchy scopes (PROJECT, ENVIRONMENT, COMPONENT) cascade values downward to instances, deployments, and resources. REPO scope applies to OCI repositories; the bundle name propagates to derived components, instances, deployments, and resources via the md-repo system attribute.",
      "enum": ["PROJECT", "ENVIRONMENT", "COMPONENT", "REPO"]
    },
    "required": {
      "type": "boolean",
      "title": "Required",
      "description": "Whether this attribute must be set when creating a resource at the specified scope.",
      "default": true
    },
    "values": {
      "type": "array",
      "title": "Allowed Values",
      "description": "The closed set of values this attribute may take. Must contain at least one entry, no duplicates, and may not contain the literal \"*\" (reserved for a future \"any value\" semantic).",
      "items": { "type": "string", "minLength": 1 },
      "minItems": 1,
      "uniqueItems": true,
      "examples": [["payments", "identity", "checkout"]]
    }
  }
}
