{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://datalab-platform.com/plugins/schema/plugin-entry.schema.json",
  "title": "DataLab plugin catalog entry",
  "description": "One file per plugin, named <id>.yaml, in the plugins folder.",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "name", "repository", "releases"],
  "properties": {
    "id": {
      "description": "Stable plugin ID, equal to PluginInfo.id. The org.datalab. prefix is reserved for DataLab-Platform plugins.",
      "type": "string",
      "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)+$"
    },
    "name": {
      "description": "Display name.",
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "kind": {
      "description": "Distribution format, not a functional plugin category. Defaults to wheel.",
      "enum": ["wheel", "module"]
    },
    "summary": {"type": "string", "minLength": 1},
    "license": {"type": "string", "minLength": 1},
    "repository": {
      "description": "Public source repository, also used to find GitHub releases.",
      "type": "string",
      "pattern": "^https://github\\.com/[A-Za-z0-9-]+/[A-Za-z0-9._-]+$"
    },
    "documentation": {
      "description": "Documentation URL, if different from the repository.",
      "type": "string",
      "pattern": "^https://"
    },
    "icon": {
      "description": "Optional HTTPS URL of an existing image, displayed in the web catalog. Initials are used if the image cannot be loaded.",
      "type": "string",
      "pattern": "^https://[^/?#\\s]+(?:[/?#][^\\s]*)?$"
    },
    "capabilities": {
      "type": "array",
      "uniqueItems": true,
      "items": {"enum": ["processing", "io", "visualization", "application"]}
    },
    "keywords": {
      "type": "array",
      "uniqueItems": true,
      "maxItems": 10,
      "items": {"type": "string", "minLength": 1, "maxLength": 40}
    },
    "status": {
      "description": "deprecated: still installable, with a warning. revoked: no longer installable.",
      "enum": ["active", "deprecated", "revoked"]
    },
    "status_reason": {"type": "string", "minLength": 1},
    "releases": {
      "type": "array",
      "minItems": 1,
      "items": {"$ref": "#/$defs/release"}
    }
  },
  "allOf": [
    {
      "if": {"properties": {"kind": {"const": "module"}}, "required": ["kind"]},
      "then": {
        "required": ["summary", "license"],
        "properties": {
          "releases": {
            "items": {
              "required": ["filename"],
              "properties": {
                "source": {"const": "github"},
                "dependency_wheels": {"maxItems": 0}
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {"status": {"enum": ["deprecated", "revoked"]}},
        "required": ["status"]
      },
      "then": {"required": ["status_reason"]}
    }
  ],
  "$defs": {
    "release": {
      "type": "object",
      "additionalProperties": false,
      "required": ["version"],
      "properties": {
        "version": {"type": "string", "minLength": 1},
        "filename": {
          "description": "Exact GitHub release asset for a single-file module.",
          "type": "string",
          "pattern": "^datalab_[A-Za-z0-9_]+\\.py$"
        },
        "requires_python": {
          "description": "Optional Python compatibility constraint for a module release.",
          "type": "string"
        },
        "sha256": {
          "description": "SHA-256 digest of the wheel. The catalog check prints it when missing.",
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "source": {
          "description": "Where the wheel is published (default: github).",
          "enum": ["github", "pypi"]
        },
        "tag": {
          "description": "GitHub release tag (default: v<version>).",
          "type": "string",
          "minLength": 1
        },
        "distribution": {
          "description": "PyPI distribution name, required for the pypi source.",
          "type": "string",
          "minLength": 1
        },
        "yanked": {
          "description": "Reason why this release should no longer be installed.",
          "type": "string",
          "minLength": 1
        },
        "dependency_wheels": {
          "description": "Reviewed additional Desktop dependency wheels, including transitive dependencies.",
          "type": "array",
          "items": {"$ref": "#/$defs/dependency-wheel"}
        }
      },
      "allOf": [
        {
          "if": {"properties": {"source": {"const": "pypi"}}, "required": ["source"]},
          "then": {"required": ["distribution"]}
        }
      ]
    },
    "dependency-wheel": {
      "type": "object",
      "additionalProperties": false,
      "required": ["filename", "url", "sha256"],
      "properties": {
        "filename": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9_.+-]*\\.whl$"
        },
        "url": {"type": "string", "pattern": "^https://"},
        "sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"}
      }
    }
  }
}
