{
  "openapi": "3.0.3",
  "info": {
    "title": "KingshotPro Kingdom Data API",
    "version": "1.0.0",
    "description": "Public kingdom-level facts for Kingshot and our own strength tier. Unofficial fan data, not affiliated with Century Games. Replies are cached for one hour; please cache on your side and do not poll faster than once an hour. Please link to kingshotpro.com when you show our tiers. Fields may be added; do not rely on field order. Send your own User-Agent header.",
    "contact": {
      "url": "https://kingshotpro.com/kingdom-data-api.html"
    }
  },
  "servers": [
    {
      "url": "https://kingshotpro-api.kingshotpro.workers.dev"
    }
  ],
  "paths": {
    "/kingdoms/index": {
      "get": {
        "operationId": "getKingdomIndex",
        "summary": "Every kingdom",
        "responses": {
          "200": {
            "description": "The whole index.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "count",
                    "generated",
                    "kingdoms"
                  ],
                  "properties": {
                    "count": {
                      "type": "integer",
                      "description": "How many kingdoms are listed."
                    },
                    "generated": {
                      "type": "string",
                      "description": "The date the index was built.",
                      "format": "date"
                    },
                    "kingdoms": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Kingdom"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/kingdoms/{id}": {
      "get": {
        "operationId": "getKingdom",
        "summary": "One kingdom",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The kingdom number.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One kingdom, the same as its entry in the index.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Kingdom"
                }
              }
            }
          },
          "400": {
            "description": "The id is not a kingdom number (error bad_id).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such kingdom in the index (error not_found).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Kingdom": {
        "type": "object",
        "required": [
          "id",
          "group",
          "power_cap",
          "leading_cap",
          "opened",
          "opened_is_bound",
          "kvk",
          "last_season",
          "tier"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "description": "The kingdom number."
          },
          "group": {
            "type": "string",
            "description": "The transfer group, a string from 1 to 11. Null when the kingdom is not in a transfer group.",
            "nullable": true
          },
          "power_cap": {
            "type": "integer",
            "description": "The normal power cap of the transfer group, in plain units. Null when there is no group. Power caps shown are those of the kingdom's transfer group in the latest window listed on the public transfer history (a tier). The King of a kingdom sets the cap their kingdom uses each window, so read the cap on your transfer screen.",
            "nullable": true
          },
          "leading_cap": {
            "type": "integer",
            "description": "The leading power cap of the transfer group. Null when there is no group. Do not use it to filter. Power caps shown are those of the kingdom's transfer group in the latest window listed on the public transfer history (a tier). The King of a kingdom sets the cap their kingdom uses each window, so read the cap on your transfer screen.",
            "nullable": true
          },
          "opened": {
            "type": "string",
            "description": "A date (YYYY-MM-DD) on or before which the kingdom opened. A bound, not an exact day.",
            "format": "date"
          },
          "opened_is_bound": {
            "type": "boolean",
            "description": "True when opened is that bound."
          },
          "kvk": {
            "type": "array",
            "description": "One entry per season, oldest first.",
            "items": {
              "$ref": "#/components/schemas/KvkSeason"
            }
          },
          "last_season": {
            "type": "integer",
            "description": "The last KvK season in which the kingdom appears."
          },
          "tier": {
            "type": "string",
            "description": "Our own strength tier, worked out from public KvK results. It shows who has been winning KvK games and nothing else. Null under 12 games.",
            "nullable": true,
            "enum": [
              "S",
              "A",
              "B",
              "C",
              "D"
            ]
          }
        }
      },
      "KvkSeason": {
        "type": "object",
        "required": [
          "season",
          "opponent",
          "prep",
          "castle",
          "bye"
        ],
        "properties": {
          "season": {
            "type": "integer",
            "description": "The KvK season number."
          },
          "opponent": {
            "type": "integer",
            "description": "The opposing kingdom number. Null for a bye.",
            "nullable": true
          },
          "prep": {
            "type": "string",
            "description": "W if this kingdom won the preparation game, L if it lost. Null for a bye or a game not decided yet.",
            "nullable": true,
            "enum": [
              "W",
              "L"
            ]
          },
          "castle": {
            "type": "string",
            "description": "W or L for the castle game. Null for a bye or a game not decided yet.",
            "nullable": true,
            "enum": [
              "W",
              "L"
            ]
          },
          "bye": {
            "type": "boolean",
            "description": "True when the kingdom had a bye that season."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  }
}
