{
  "openapi": "3.1.0",
  "info": {
    "title": "Saga Antípodas public knowledge API",
    "version": "v4-expansion-95a8ffb089ab518df82f"
  },
  "servers": [
    {
      "url": "https://sagaantipodas.com"
    }
  ],
  "paths": {
    "/api/ia/v4/capabilities": {
      "get": {
        "operationId": "capabilities",
        "responses": {
          "200": {
            "description": "Public capabilities",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/ia/v4/query": {
      "get": {
        "operationId": "queryKnowledge",
        "parameters": [
          {
            "name": "operation",
            "in": "query",
            "required": true,
            "schema": {
              "enum": [
                "search",
                "record",
                "entity",
                "relations",
                "places",
                "events",
                "rules",
                "exceptions",
                "cards",
                "asset_by_card",
                "source_status",
                "fragment"
              ]
            }
          },
          {
            "name": "query",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 200,
              "pattern": "^[^\\u0000-\\u001f]*$"
            }
          },
          {
            "name": "id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^sa:[a-zA-Z0-9:_-]{1,160}$"
            }
          },
          {
            "name": "game_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^sa:game:[a-z0-9-]{1,80}$"
            }
          },
          {
            "name": "card_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9-]{1,100}$"
            }
          },
          {
            "name": "version",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            }
          },
          {
            "name": "domain",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "rules",
                "entities",
                "geography",
                "chronology",
                "media",
                "sources"
              ]
            }
          },
          {
            "name": "language",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "es",
                "en",
                "nl",
                "fr",
                "de",
                "it",
                "pt",
                "tr"
              ]
            }
          },
          {
            "name": "fallback_language",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "none",
                "es"
              ]
            }
          },
          {
            "name": "spoiler_level",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "none",
                "premise",
                "chapter",
                "major",
                "ending"
              ]
            }
          },
          {
            "name": "context",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "reference",
                "active_game",
                "rule_explanation",
                "card_identification",
                "historical_research"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 20
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 700,
              "pattern": "^[A-Za-z0-9_-]+$"
            }
          },
          {
            "name": "depth",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "compact",
                "detailed"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized public records only",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Response"
                }
              }
            }
          },
          "304": {
            "description": "Not modified"
          },
          "400": {
            "description": "Invalid query"
          },
          "413": {
            "description": "Response budget exceeded"
          },
          "429": {
            "description": "Admission limit"
          },
          "503": {
            "description": "Safe unavailable error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Request": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://sagaantipodas.com/ia/v4/request.schema.json",
        "type": "object",
        "required": [
          "operation"
        ],
        "additionalProperties": false,
        "properties": {
          "operation": {
            "enum": [
              "search",
              "record",
              "entity",
              "relations",
              "places",
              "events",
              "rules",
              "exceptions",
              "cards",
              "asset_by_card",
              "source_status",
              "fragment"
            ]
          },
          "query": {
            "type": "string",
            "minLength": 2,
            "maxLength": 200,
            "pattern": "^[^\\u0000-\\u001f]*$"
          },
          "id": {
            "type": "string",
            "pattern": "^sa:[a-zA-Z0-9:_-]{1,160}$"
          },
          "game_id": {
            "type": "string",
            "pattern": "^sa:game:[a-z0-9-]{1,80}$"
          },
          "card_id": {
            "type": "string",
            "pattern": "^[a-z0-9-]{1,100}$"
          },
          "version": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "domain": {
            "enum": [
              "rules",
              "entities",
              "geography",
              "chronology",
              "media",
              "sources"
            ]
          },
          "language": {
            "enum": [
              "es",
              "en",
              "nl",
              "fr",
              "de",
              "it",
              "pt",
              "tr"
            ]
          },
          "fallback_language": {
            "enum": [
              "none",
              "es"
            ]
          },
          "spoiler_level": {
            "enum": [
              "none",
              "premise",
              "chapter",
              "major",
              "ending"
            ]
          },
          "context": {
            "enum": [
              "reference",
              "active_game",
              "rule_explanation",
              "card_identification",
              "historical_research"
            ]
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20
          },
          "cursor": {
            "type": "string",
            "maxLength": 700,
            "pattern": "^[A-Za-z0-9_-]+$"
          },
          "depth": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1
          },
          "format": {
            "enum": [
              "compact",
              "detailed"
            ]
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "operation": {
                  "const": "search"
                }
              }
            },
            "then": {
              "required": [
                "query"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "operation": {
                  "enum": [
                    "rules",
                    "exceptions",
                    "cards",
                    "asset_by_card"
                  ]
                }
              }
            },
            "then": {
              "required": [
                "game_id"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "operation": {
                  "const": "asset_by_card"
                }
              }
            },
            "then": {
              "required": [
                "card_id"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "operation": {
                  "enum": [
                    "record",
                    "entity",
                    "relations",
                    "source_status",
                    "fragment"
                  ]
                }
              }
            },
            "then": {
              "required": [
                "id"
              ]
            }
          }
        ]
      },
      "Response": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://sagaantipodas.com/ia/v4/response.schema.json",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "status",
          "knowledge_version",
          "operation",
          "results",
          "next_cursor",
          "reference",
          "warnings"
        ],
        "properties": {
          "status": {
            "enum": [
              "ok",
              "no_results"
            ]
          },
          "knowledge_version": {
            "type": "string"
          },
          "operation": {
            "enum": [
              "search",
              "record",
              "entity",
              "relations",
              "places",
              "events",
              "rules",
              "exceptions",
              "cards",
              "asset_by_card",
              "source_status",
              "fragment"
            ]
          },
          "results": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "object",
              "required": [
                "id",
                "type",
                "title",
                "language",
                "game_id",
                "version",
                "spoiler_level",
                "canonical_status",
                "provenance",
                "reference",
                "content"
              ],
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^sa:"
                },
                "type": {
                  "type": "string"
                },
                "title": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "language": {
                  "type": "string"
                },
                "game_id": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "version": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "spoiler_level": {
                  "enum": [
                    "none",
                    "premise",
                    "chapter",
                    "major",
                    "ending"
                  ]
                },
                "canonical_status": {
                  "type": "string"
                },
                "provenance": {
                  "type": "array",
                  "maxItems": 8,
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "reference_id",
                      "source_id",
                      "locator",
                      "sha256"
                    ],
                    "properties": {
                      "reference_id": {
                        "type": "string"
                      },
                      "source_id": {
                        "type": "string"
                      },
                      "locator": {
                        "type": "string"
                      },
                      "sha256": {
                        "type": "string",
                        "pattern": "^[a-f0-9]{64}$"
                      }
                    }
                  }
                },
                "reference": {
                  "const": "https://sagaantipodas.com/ia/"
                },
                "content": {
                  "type": [
                    "object",
                    "null"
                  ]
                },
                "asset": {
                  "type": "object",
                  "required": [
                    "url",
                    "sha256"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "url": {
                      "type": "string",
                      "pattern": "^https://sagaantipodas\\.com/ia/"
                    },
                    "sha256": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    }
                  }
                }
              }
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "reference": {
            "const": "https://sagaantipodas.com/ia/"
          },
          "warnings": {
            "type": "array",
            "maxItems": 5,
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "x-query-validation": "Request schema allOf requirements apply after GET parameter parsing. No POST, internal or admin operation."
}
