{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aniworks.net/schemas/mapping-manifest-v1.json",
  "title": "Mapping standard: aniworks.json manifest, version 1",
  "description": "Served at /.well-known/aniworks.json. See https://aniworks.net/docs/mapping",
  "type": "object",
  "required": ["version", "name"],
  "anyOf": [{ "required": ["anime"] }, { "required": ["manga"] }],
  "properties": {
    "version": { "const": 1 },
    "name": { "type": "string", "minLength": 1, "maxLength": 64 },
    "icon": { "$ref": "#/$defs/path" },
    "anime": {
      "type": "object",
      "required": ["url", "patterns", "catalog"],
      "properties": {
        "url": { "$ref": "#/$defs/animeTemplate" },
        "patterns": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10,
          "items": { "$ref": "#/$defs/animePattern" }
        },
        "catalog": { "$ref": "#/$defs/path" }
      }
    },
    "manga": {
      "type": "object",
      "required": ["url", "patterns", "catalog"],
      "properties": {
        "url": { "$ref": "#/$defs/mangaTemplate" },
        "patterns": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10,
          "items": { "$ref": "#/$defs/mangaPattern" }
        },
        "catalog": { "$ref": "#/$defs/path" }
      }
    }
  },
  "$defs": {
    "path": {
      "description": "A path on the domain serving the manifest",
      "type": "string",
      "pattern": "^/(?!/)\\S*$",
      "maxLength": 2048
    },
    "animeTemplate": {
      "description": "A path with {id}, and optionally {ep}",
      "type": "string",
      "pattern": "^/(?!/)\\S*\\{id\\}",
      "not": { "pattern": "\\{(?!id\\}|ep\\})" },
      "maxLength": 2048
    },
    "mangaTemplate": {
      "description": "A path with {id}, and optionally {ch}",
      "type": "string",
      "pattern": "^/(?!/)\\S*\\{id\\}",
      "not": { "pattern": "\\{(?!id\\}|ch\\})" },
      "maxLength": 2048
    },
    "animePattern": {
      "description": "A path with {id} and {ep}, and optionally {*}",
      "type": "string",
      "allOf": [{ "pattern": "^/(?!/)\\S*\\{id\\}" }, { "pattern": "\\{ep\\}" }],
      "not": { "pattern": "\\{(?!id\\}|ep\\}|\\*\\})" },
      "maxLength": 2048
    },
    "mangaPattern": {
      "description": "A path with {id} and {ch}, and optionally {*}",
      "type": "string",
      "allOf": [{ "pattern": "^/(?!/)\\S*\\{id\\}" }, { "pattern": "\\{ch\\}" }],
      "not": { "pattern": "\\{(?!id\\}|ch\\}|\\*\\})" },
      "maxLength": 2048
    }
  }
}
