{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://govschema.org/spec/v0.1/govschema.schema.json",
  "title": "GovSchema Document",
  "description": "Meta-schema for a GovSchema document: a versioned, machine-readable definition of a government form or process. A document that validates against this meta-schema is a well-formed GovSchema schema. This is a standards artifact published by the GovSchema foundation; it does not imply endorsement by any government.",
  "type": "object",
  "required": [
    "$schema",
    "govschemaVersion",
    "id",
    "version",
    "title",
    "status",
    "jurisdiction",
    "authority",
    "source",
    "verification",
    "fields"
  ],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string",
      "format": "uri",
      "description": "URI of the GovSchema meta-schema this document conforms to."
    },
    "govschemaVersion": {
      "type": "string",
      "$ref": "#/$defs/semver",
      "description": "Version of the GovSchema specification this document targets."
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z]{2}(/[a-z0-9-]+){2,}$",
      "description": "Registry identifier, equal to the document's path under registry/ (excluding version). Lowercase, slash-separated, starting with an ISO 3166-1 alpha-2 country code. Example: us/ca/dmv/vehicle-registration-renewal"
    },
    "version": {
      "type": "string",
      "$ref": "#/$defs/semver",
      "description": "Semantic version of THIS schema. See VERSIONING.md for what MAJOR/MINOR/PATCH mean for a schema."
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": ["draft", "verified", "deprecated"],
      "description": "Lifecycle status. 'verified' requires a current verification record matching the live source."
    },
    "jurisdiction": {
      "type": "object",
      "required": ["country", "level"],
      "additionalProperties": false,
      "properties": {
        "country": {
          "type": "string",
          "pattern": "^[A-Z]{2}$",
          "description": "ISO 3166-1 alpha-2 country code (uppercase)."
        },
        "subdivision": {
          "type": "string",
          "pattern": "^[A-Z]{2}-[A-Z0-9]{1,3}$",
          "description": "ISO 3166-2 subdivision code, when the process is subnational. Example: US-CA"
        },
        "level": {
          "type": "string",
          "enum": ["national", "subnational", "municipal", "supranational"]
        }
      }
    },
    "authority": {
      "type": "object",
      "required": ["name"],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "abbreviation": { "type": "string" },
        "url": { "type": "string", "format": "uri" }
      }
    },
    "process": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": {
          "type": "string",
          "enum": ["application", "registration", "renewal", "amendment", "filing", "request", "other"]
        },
        "language": {
          "type": "string",
          "description": "BCP-47 language tag of the source form. Example: en-US"
        }
      }
    },
    "source": {
      "type": "object",
      "description": "The live government source this schema was derived from.",
      "required": ["url", "retrievedAt"],
      "additionalProperties": false,
      "properties": {
        "url": { "type": "string", "format": "uri" },
        "retrievedAt": { "type": "string", "format": "date" },
        "documentRef": {
          "type": "string",
          "description": "Official form number or document reference, when one exists. Example: REG 156"
        }
      }
    },
    "verification": {
      "type": "object",
      "description": "Record of how and when this schema was confirmed against the live source. See practices/ for methods.",
      "required": ["method", "lastVerifiedAt"],
      "additionalProperties": false,
      "properties": {
        "method": {
          "type": "string",
          "description": "Identifier of the verification practice used. Example: manual-source-review-v1"
        },
        "lastVerifiedAt": { "type": "string", "format": "date" },
        "verifiedBy": { "type": "string" },
        "nextReviewBy": { "type": "string", "format": "date" },
        "notes": { "type": "string" }
      }
    },
    "license": {
      "type": "string",
      "description": "SPDX or Creative Commons identifier under which this schema content is published. Example: CC-BY-4.0"
    },
    "fields": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/field" }
    },
    "steps": {
      "type": "array",
      "description": "Optional ordered description of the process flow.",
      "items": { "$ref": "#/$defs/step" }
    }
  },
  "$defs": {
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-[0-9A-Za-z-.]+)?(?:\\+[0-9A-Za-z-.]+)?$"
    },
    "field": {
      "type": "object",
      "required": ["name", "label", "type"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z][a-zA-Z0-9_]*$",
          "description": "Stable machine key for the field."
        },
        "label": {
          "type": "string",
          "description": "Human-facing label as it appears on the source form."
        },
        "type": {
          "type": "string",
          "enum": ["string", "number", "integer", "boolean", "date", "enum", "file", "object"]
        },
        "required": { "type": "boolean", "default": false },
        "description": { "type": "string" },
        "sourceRef": {
          "type": "string",
          "description": "Where this field appears on the source form. Example: Section 2, Box 4a"
        },
        "validation": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "pattern": { "type": "string" },
            "minLength": { "type": "integer", "minimum": 0 },
            "maxLength": { "type": "integer", "minimum": 0 },
            "minimum": { "type": "number" },
            "maximum": { "type": "number" },
            "enum": { "type": "array", "items": {} }
          }
        }
      }
    },
    "step": {
      "type": "object",
      "required": ["id", "title"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z][a-zA-Z0-9_-]*$" },
        "title": { "type": "string" },
        "fields": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Names of fields collected in this step."
        },
        "next": {
          "type": "string",
          "description": "id of the next step, or omitted for the final step."
        }
      }
    }
  }
}
