{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/source-maps/source-map.v1.schema.json",
  "title": "RootBlocks Source Map v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "mapId",
    "projectId",
    "workflowId",
    "standard",
    "artifacts",
    "links"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.source-map/v1"
    },
    "mapId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "projectId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "workflowId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "standard": {
      "$ref": "#/$defs/standardRef"
    },
    "artifacts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["spec", "workflow"],
      "properties": {
        "spec": {
          "$ref": "#/$defs/artifact"
        },
        "workflow": {
          "$ref": "#/$defs/artifact"
        },
        "regressionSuite": {
          "$ref": "#/$defs/artifact"
        }
      }
    },
    "links": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/link"
      }
    }
  },
  "$defs": {
    "standardRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundleId", "version", "hash"],
      "properties": {
        "bundleId": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[A-Za-z0-9.-]+)?(\\+[A-Za-z0-9.-]+)?$"
        },
        "hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64,128}$"
        }
      }
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "hash"],
      "properties": {
        "path": {
          "type": "string",
          "minLength": 1
        },
        "hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64,128}$"
        }
      }
    },
    "link": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "criticality",
        "specRefs",
        "workflowNodeId",
        "generatedCodeRefs",
        "regressionCaseRefs"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
        },
        "criticality": {
          "enum": ["low", "medium", "high", "critical"]
        },
        "specRefs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/specRef"
          }
        },
        "workflowNodeId": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
        },
        "generatedCodeRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/codeRef"
          }
        },
        "regressionCaseRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
          }
        },
        "evidenceRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
          }
        }
      }
    },
    "specRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sectionId"],
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^docs/specs/.+\\.md$"
        },
        "sectionId": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.:-]{1,120}$"
        }
      }
    },
    "codeRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path"],
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^(src|tests|builderx)/.+$"
        },
        "symbol": {
          "type": "string",
          "maxLength": 240
        }
      }
    }
  }
}

