{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.elastic-print.io/hdm-metadata/2",
  "title": ".hdm-metadata.yml",
  "description": "Schema for validating HDM metadata YAML files. Declaring metadata is an assistance, not an enforcement: only the format identity and ownership are required, every classification and integration block is optional. A block that is present must carry its identifying field, so a block is either absent or meaningful. Absence is expressed by omitting a field; 'n/a' placeholder values are obsolete.",
  "type": "object",
  "required": ["schema", "responsible"],
  "properties": {
    "schema": {
      "type": "object",
      "description": "Self-describing format identity. Consumers read 'version' from the parsed document to select the validating schema; versions are never discriminated by trying each published schema in turn.",
      "required": ["name", "version"],
      "properties": {
        "name": {
          "type": "string",
          "const": "hdm-metadata",
          "description": "The schema name must be 'hdm-metadata'."
        },
        "version": {
          "type": "integer",
          "const": 2,
          "description": "The schema version. Must be exactly 2 for this schema."
        }
      },
      "additionalProperties": false
    },
    "responsible": {
      "type": "object",
      "description": "Ownership of the software. The only mandatory block besides the format identity.",
      "required": ["persons"],
      "properties": {
        "persons": {
          "type": "array",
          "minItems": 1,
          "description": "List of responsible persons (at least one required).",
          "items": {
            "type": "string",
            "format": "email",
            "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
            "description": "Valid email address."
          }
        },
        "teams": {
          "type": "array",
          "description": "List of responsible teams (optional).",
          "items": {
            "type": "string",
            "minLength": 1,
            "description": "Team name."
          }
        }
      },
      "additionalProperties": false
    },
    "project": {
      "type": "object",
      "description": "Optional classification of the software itself: how it is delivered and which products it belongs to.",
      "properties": {
        "usage_contexts": {
          "type": "array",
          "description": "Optional list of contexts in which the software is deployed and used.",
          "items": {
            "type": "string",
            "enum": ["in_house", "on_premises", "saas"],
            "description": "Usage context: 'in_house' (used internally only), 'on_premises' (installed at customer sites), or 'saas' (operated as a hosted service)."
          }
        },
        "product_affiliations": {
          "type": "array",
          "description": "Optional list of products this software belongs to or contributes to.",
          "items": {
            "type": "string",
            "minLength": 1,
            "description": "Product name."
          }
        }
      },
      "additionalProperties": false
    },
    "gitlab": {
      "type": "object",
      "description": "Optional GitLab binding and state to be projected onto the GitLab project. If this block is present, 'project_id' is required.",
      "required": ["project_id"],
      "properties": {
        "project_id": {
          "type": "integer",
          "minimum": 1,
          "description": "GitLab project ID. An assertion to verify against the authoritative project identity, not a selector for which project to write to."
        },
        "project_url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https?://[^\\s]+$",
          "minLength": 1,
          "description": "Optional GitLab project URL."
        },
        "description": {
          "type": "string",
          "description": "Optional project description to apply to the GitLab project."
        },
        "topics": {
          "type": "array",
          "description": "Optional escape hatch for additional GitLab repository topics. Carries ONLY topics that cannot be derived from structured fields. Topics derived from 'responsible', 'project.product_affiliations', 'project.usage_contexts', or 'jira.domains' are owned by the consuming service and must not be restated here.",
          "items": {
            "type": "string",
            "minLength": 1,
            "description": "Additional topic that is not derivable from any structured field."
          }
        }
      },
      "additionalProperties": false
    },
    "jira": {
      "type": "object",
      "description": "Optional reference to the Jira records related to this project. If this block is present, 'domains' is required.",
      "required": ["domains"],
      "properties": {
        "domains": {
          "type": "array",
          "minItems": 1,
          "description": "List of Jira domains this project belongs to.",
          "items": {
            "type": "string",
            "minLength": 1,
            "description": "Jira domain name."
          }
        }
      },
      "additionalProperties": false
    },
    "jenkins": {
      "type": "object",
      "description": "Optional reference to the Jenkins jobs building this project. If this block is present, 'jobs' is required.",
      "required": ["jobs"],
      "properties": {
        "jobs": {
          "type": "array",
          "minItems": 1,
          "description": "List of Jenkins job URLs.",
          "items": {
            "type": "string",
            "format": "uri",
            "pattern": "^https?://[^\\s]+$",
            "minLength": 1,
            "description": "Jenkins job URL."
          }
        }
      },
      "additionalProperties": false
    },
    "sonarqube": {
      "type": "object",
      "description": "Optional SonarQube binding. If this block is present, 'project_key' is required.",
      "required": ["project_key"],
      "properties": {
        "project_key": {
          "type": "string",
          "minLength": 1,
          "description": "SonarQube project key."
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
