{
  "openapi": "3.0.3",
  "info": {
    "title": "图解中医共享阅读 API",
    "version": "1.0.0",
    "description": "网站与安卓客户端共用的只读内容接口。图片和文件 URL 相对服务根地址解析。无需 GitHub 凭据。"
  },
  "servers": [
    {
      "url": "/api/v1"
    }
  ],
  "paths": {
    "/albums": {
      "get": {
        "summary": "图集列表",
        "description": "",
        "parameters": [
          {
            "name": "include",
            "in": "query",
            "required": false,
            "description": "省略时返回轻量列表；sections 附带完整条文和图片清单。",
            "schema": {
              "type": "string",
              "enum": [
                "sections"
              ]
            }
          },
          {
            "name": "refresh",
            "in": "query",
            "required": false,
            "description": "主动刷新时使用，常规请求省略。",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Catalog"
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "内容服务暂不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "listAlbums"
      }
    },
    "/albums/{albumId}": {
      "get": {
        "summary": "图集详情",
        "description": "",
        "parameters": [
          {
            "name": "albumId",
            "in": "path",
            "required": true,
            "description": "",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Album"
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "内容服务暂不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "getAlbum"
      }
    },
    "/albums/{albumId}/sections": {
      "get": {
        "summary": "按阅读顺序分页获取条文目录",
        "description": "",
        "parameters": [
          {
            "name": "albumId",
            "in": "path",
            "required": true,
            "description": "",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "description": "",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9999999,
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Directory"
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "内容服务暂不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "listSections"
      }
    },
    "/sections/{sectionId}": {
      "get": {
        "summary": "条文原文、图解及前后导航",
        "description": "已有图解而原文缺失或暂不可用时仍返回 200，以 sourceStatus 区分状态。仅提供 originalClause，不包含完整 Markdown 讲解。",
        "parameters": [
          {
            "name": "sectionId",
            "in": "path",
            "required": true,
            "description": "使用响应中的 id 或 sectionId，整体百分号编码。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SectionDetail"
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "内容服务暂不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "getSection"
      }
    },
    "/sections/{sectionId}/similar": {
      "get": {
        "summary": "相似条文",
        "description": "文本相似度推荐，不代表不同讲者之间经过确认的同条对应。索引准备中返回 status=indexing。",
        "parameters": [
          {
            "name": "sectionId",
            "in": "path",
            "required": true,
            "description": "使用响应中的 id 或 sectionId，整体百分号编码。",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "省略时返回全部匹配；1–5 返回排名靠前的条文，且每条附带全部 pages。",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 5
            }
          },
          {
            "name": "retry",
            "in": "query",
            "required": false,
            "description": "用户主动重试时请求重新准备索引，常规请求省略。",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IndexResults"
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "内容服务暂不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "getSimilarSections"
      }
    },
    "/search": {
      "get": {
        "summary": "搜索条文标题和原文",
        "description": "每页 20 条。ready 时使用 nextOffset；null 表示最后一页。indexing 时短暂等待后重试，不能视为没有结果。",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "",
            "schema": {
              "type": "string",
              "maxLength": 160
            }
          },
          {
            "name": "album",
            "in": "query",
            "required": false,
            "description": "可选图集 ID；省略搜索全部图集。",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "description": "",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9999999,
              "default": 0
            }
          },
          {
            "name": "retry",
            "in": "query",
            "required": false,
            "description": "用户主动重试时请求重新准备索引，常规请求省略。",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IndexResults"
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "内容服务暂不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "searchSections"
      }
    },
    "/ebooks": {
      "get": {
        "summary": "电纸书目录",
        "description": "",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": false,
            "description": "目录相对路径；省略为根目录，文件返回 download 地址。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ebooks"
                }
              }
            }
          },
          "400": {
            "description": "参数无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "资源不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "内容服务暂不可用",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "listEbooks"
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "code"
        ]
      },
      "Image": {
        "type": "object",
        "properties": {
          "number": {
            "type": "integer",
            "minimum": 0
          },
          "src": {
            "type": "string",
            "description": "相对服务根地址的图片 URL；按原样解析，不拼接 GitHub 地址。"
          },
          "version": {
            "type": "string"
          },
          "bytes": {
            "type": "integer",
            "minimum": 0
          },
          "repoPath": {
            "type": "string",
            "description": "稳定图片定位键，用于恢复已有阅读进度；不应解析其目录结构。"
          }
        },
        "required": [
          "src",
          "version",
          "repoPath"
        ]
      },
      "Stats": {
        "type": "object",
        "properties": {
          "collections": {
            "type": "integer",
            "minimum": 0
          },
          "sections": {
            "type": "integer",
            "minimum": 0
          },
          "pages": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "collections",
          "sections",
          "pages"
        ]
      },
      "Section": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "图集 ID 与条文 key 组成的全局 ID。调用方作为不透明字符串，放入 URL 时整体百分号编码。"
          },
          "albumId": {
            "type": "string"
          },
          "key": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "articleNo": {
            "type": "string",
            "nullable": true
          },
          "pageCount": {
            "type": "integer",
            "minimum": 0
          },
          "firstImage": {
            "$ref": "#/components/schemas/Image"
          },
          "version": {
            "type": "string"
          },
          "pages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Image"
            },
            "description": "仅 include=sections 的图集列表和条文详情返回；按顺序阅读。"
          }
        },
        "required": [
          "id",
          "albumId",
          "key",
          "title",
          "pageCount",
          "firstImage",
          "version"
        ]
      },
      "SectionDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Section"
          },
          {
            "type": "object",
            "properties": {
              "originalClause": {
                "type": "string"
              },
              "sourceTitle": {
                "type": "string"
              },
              "sourceStatus": {
                "type": "string",
                "enum": [
                  "available",
                  "missing",
                  "unavailable"
                ]
              },
              "previousSectionId": {
                "type": "string",
                "nullable": true
              },
              "nextSectionId": {
                "type": "string",
                "nullable": true
              }
            },
            "required": [
              "originalClause",
              "sourceTitle",
              "sourceStatus",
              "previousSectionId",
              "nextSectionId"
            ]
          }
        ]
      },
      "Album": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "clauses",
              "summaries"
            ]
          },
          "unit": {
            "type": "string"
          },
          "tagline": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "sectionCount": {
            "type": "integer",
            "minimum": 0
          },
          "pageCount": {
            "type": "integer",
            "minimum": 0
          },
          "bytes": {
            "type": "integer",
            "minimum": 0
          },
          "firstImage": {
            "$ref": "#/components/schemas/Image"
          },
          "version": {
            "type": "string"
          },
          "sections": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Section"
            }
          }
        },
        "required": [
          "id",
          "name",
          "kind",
          "sectionCount",
          "pageCount",
          "version"
        ]
      },
      "Catalog": {
        "type": "object",
        "properties": {
          "collections": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Album"
            }
          },
          "stats": {
            "$ref": "#/components/schemas/Stats"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "string"
          }
        },
        "required": [
          "collections",
          "stats",
          "generatedAt",
          "version"
        ]
      },
      "Directory": {
        "type": "object",
        "properties": {
          "albumId": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "sections": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Section"
            }
          },
          "nextOffset": {
            "type": "integer",
            "nullable": true,
            "minimum": 0
          }
        },
        "required": [
          "albumId",
          "version",
          "total",
          "sections",
          "nextOffset"
        ]
      },
      "Match": {
        "type": "object",
        "properties": {
          "sectionId": {
            "type": "string"
          },
          "albumId": {
            "type": "string"
          },
          "albumName": {
            "type": "string"
          },
          "sectionKey": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "sourceTitle": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "pageCount": {
            "type": "integer",
            "minimum": 0
          },
          "image": {
            "type": "string"
          },
          "score": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "pages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Image"
            }
          }
        },
        "required": [
          "sectionId",
          "albumId",
          "sectionKey"
        ]
      },
      "IndexResults": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ready",
              "indexing"
            ]
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Match"
            }
          },
          "processed": {
            "type": "integer",
            "minimum": 0
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "indexed": {
            "type": "integer",
            "minimum": 0
          },
          "totalMatches": {
            "type": "integer",
            "minimum": 0
          },
          "nextOffset": {
            "type": "integer",
            "nullable": true
          },
          "queryAvailable": {
            "type": "boolean"
          },
          "unavailable": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "albumId": {
                  "type": "string"
                },
                "sectionKey": {
                  "type": "string"
                }
              },
              "required": []
            }
          }
        },
        "required": [
          "status",
          "results"
        ]
      },
      "EbookEntry": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "folder",
              "file"
            ]
          },
          "name": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "files": {
            "type": "integer",
            "minimum": 0
          },
          "bytes": {
            "type": "integer",
            "minimum": 0
          },
          "extension": {
            "type": "string"
          },
          "download": {
            "type": "string",
            "description": "相对服务根地址的下载 URL，支持 HEAD 和 Range。"
          },
          "version": {
            "type": "string"
          }
        },
        "required": [
          "type",
          "name",
          "path",
          "bytes"
        ]
      },
      "Ebooks": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EbookEntry"
            }
          },
          "stats": {
            "type": "object",
            "properties": {
              "files": {
                "type": "integer",
                "minimum": 0
              },
              "folders": {
                "type": "integer",
                "minimum": 0
              },
              "bytes": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": []
          }
        },
        "required": [
          "name",
          "path",
          "entries",
          "stats"
        ]
      }
    }
  }
}
