{
  "openapi": "3.0.3",
  "info": {
    "title": "Wechat Articles API",
    "version": "1.2.0",
    "description": "只读公众号图文 API。上传功能不向同事开放。"
  },
  "servers": [
    {
      "url": "https://werss.ippony.com"
    }
  ],
  "security": [
    {
      "ReadToken": []
    }
  ],
  "paths": {
    "/v1/status": {
      "get": {
        "summary": "同步状态与图片完整性",
        "parameters": [
          {
            "name": "batch",
            "in": "query",
            "description": "固定到响应中的 batch_id，可读取最近三个批次；用于保持分页结果一致。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing or incorrect read token"
          },
          "404": {
            "description": "No published batch, expired batch, or resource not found"
          },
          "400": {
            "description": "日期、分页或关键词等参数无效"
          }
        }
      }
    },
    "/v1/sources": {
      "get": {
        "summary": "公众号列表",
        "parameters": [
          {
            "name": "batch",
            "in": "query",
            "description": "固定到响应中的 batch_id，可读取最近三个批次；用于保持分页结果一致。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batch_id": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or incorrect read token"
          },
          "404": {
            "description": "No published batch, expired batch, or resource not found"
          },
          "400": {
            "description": "日期、分页或关键词等参数无效"
          }
        }
      }
    },
    "/v1/articles": {
      "get": {
        "summary": "文章列表；日期按北京时间解释，包含 to 当天",
        "parameters": [
          {
            "name": "source_id",
            "in": "query",
            "description": "公众号 ID；多个 ID 以逗号分隔，匹配任一公众号。也支持重复传入 source_id；不传表示全部。",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "起始日期，包含当天",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "结束日期，包含当天",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "page",
            "in": "query",
            "description": "页码",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1,
              "maximum": 1000000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "description": "每页数量",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "batch",
            "in": "query",
            "description": "固定到响应中的 batch_id，可读取最近三个批次；用于保持分页结果一致。",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "标题或摘要关键词，不区分大小写",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "newest",
                "oldest"
              ],
              "default": "newest"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batch_id": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "page_size": {
                      "type": "integer"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ArticleSummary"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or incorrect read token"
          },
          "404": {
            "description": "No published batch, expired batch, or resource not found"
          },
          "400": {
            "description": "日期、分页或关键词等参数无效"
          }
        }
      }
    },
    "/v1/articles/{id}": {
      "get": {
        "summary": "文章详情，含正文及有效期七天的图片链接",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "batch",
            "in": "query",
            "description": "固定到响应中的 batch_id，可读取最近三个批次；用于保持分页结果一致。",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batch_id": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Article"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or incorrect read token"
          },
          "404": {
            "description": "No published batch, expired batch, or resource not found"
          },
          "400": {
            "description": "日期、分页或关键词等参数无效"
          }
        }
      }
    },
    "/v1/images/{id}": {
      "get": {
        "summary": "图片；也可直接访问详情响应中的签名 URL",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Image bytes",
            "content": {
              "image/*": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Read token required, or invalid/expired signed URL"
          },
          "400": {
            "description": "日期、分页或关键词等参数无效"
          }
        }
      }
    },
    "/v1/stats": {
      "get": {
        "summary": "按全部匹配结果统计（与分页无关）",
        "parameters": [
          {
            "name": "source_id",
            "in": "query",
            "description": "公众号 ID；多个 ID 以逗号分隔，匹配任一公众号。也支持重复传入 source_id；不传表示全部。",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "起始日期，包含当天",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "结束日期，包含当天",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "batch",
            "in": "query",
            "description": "固定到响应中的 batch_id，可读取最近三个批次；用于保持分页结果一致。",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "标题或摘要关键词，不区分大小写",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "统计结果",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batch_id": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "source_count": {
                      "type": "integer"
                    },
                    "first_date": {
                      "type": "string",
                      "nullable": true
                    },
                    "last_date": {
                      "type": "string",
                      "nullable": true
                    },
                    "daily": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string",
                            "format": "date"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    },
                    "sources": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Read token required"
          },
          "400": {
            "description": "日期、分页或关键词等参数无效"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ReadToken": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "ArticleSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "source_id": {
            "type": "string"
          },
          "source_name": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          },
          "published_at": {
            "type": "string"
          },
          "original_url": {
            "type": "string"
          },
          "image_count": {
            "type": "integer",
            "minimum": 0
          },
          "missing_images": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "id",
          "source_id",
          "title",
          "published_at"
        ]
      },
      "Article": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ArticleSummary"
          },
          {
            "type": "object",
            "properties": {
              "content_html": {
                "type": "string"
              },
              "content_text": {
                "type": "string"
              },
              "image_urls_expire_at": {
                "type": "string",
                "format": "date-time"
              },
              "images": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "mime": {
                      "type": "string"
                    },
                    "bytes": {
                      "type": "integer"
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          }
        ]
      }
    }
  }
}
