{
  "openapi": "3.1.0",
  "info": {
    "title": "晓程序啦 投稿 API",
    "version": "1.0.0",
    "description": "无需注册的审核制产品投稿。状态查询使用投稿时返回的 Bearer token。"
  },
  "servers": [
    {
      "url": "https://xcx.la"
    }
  ],
  "components": {
    "securitySchemes": {
      "receipt": {
        "type": "http",
        "scheme": "bearer"
      },
      "managementKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "原始投稿返回的 management_key，仅用于修改申请。"
      }
    },
    "schemas": {
      "Submission": {
        "type": "object",
        "required": [
          "name",
          "url",
          "summary",
          "description",
          "icon"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048
          },
          "summary": {
            "type": "string",
            "minLength": 4,
            "maxLength": 120
          },
          "description": {
            "type": "string",
            "minLength": 20,
            "maxLength": 10000
          },
          "category": {
            "type": "string",
            "enum": [
              "games",
              "interactive",
              "quizzes",
              "productivity",
              "coding",
              "automation",
              "agents",
              "utilities",
              "information",
              "showcase",
              "data",
              "models",
              "research",
              "learning",
              "writing",
              "design",
              "creation",
              "audio",
              "video",
              "podcasts",
              "events",
              "social",
              "collaboration",
              "other"
            ],
            "default": "other"
          },
          "kind": {
            "type": "string",
            "enum": [
              "product",
              "correction"
            ],
            "default": "product"
          },
          "features": {
            "type": "array",
            "maxItems": 6,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 40
            }
          },
          "source": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048
          },
          "contact": {
            "type": "string",
            "maxLength": 200
          },
          "icon": {
            "type": "string",
            "description": "必填，PNG/JPEG/WebP 的 base64 data URL，解码后不超过 2 MiB。"
          },
          "screenshot": {
            "type": "string",
            "description": "选填，一张界面截图，PNG/JPEG/WebP 的 base64 data URL，解码后不超过 2 MiB。"
          }
        }
      },
      "Receipt": {
        "type": "object",
        "required": [
          "id",
          "token",
          "status",
          "status_url"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "token": {
            "type": "string"
          },
          "status": {
            "const": "pending_review"
          },
          "status_url": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "management_key": {
            "type": "string",
            "description": "新产品投稿时仅返回一次，请安全保存。"
          },
          "manage_url": {
            "type": "string"
          }
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "enum": [
              "pending_review",
              "published",
              "rejected"
            ]
          },
          "page_url": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          },
          "updated": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/submissions": {
      "post": {
        "operationId": "submitProduct",
        "summary": "提交产品（进入待审核）",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Submission"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "已接收，保存 token 用于查询",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "409": {
            "description": "网址已收录或待审核"
          },
          "413": {
            "description": "请求超过 6 MiB"
          },
          "422": {
            "description": "参数错误，响应包含 error 和 field"
          },
          "429": {
            "description": "频率限制"
          }
        }
      }
    },
    "/api/v1/submissions/{id}": {
      "get": {
        "operationId": "getSubmissionStatus",
        "summary": "查看自己的投稿状态",
        "security": [
          {
            "receipt": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "审核状态",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          },
          "404": {
            "description": "不存在或凭据不符"
          },
          "429": {
            "description": "查询过于频繁"
          }
        }
      },
      "patch": {
        "operationId": "reviseSubmission",
        "summary": "修改待审核投稿或为已发布产品提交修改申请",
        "description": "使用原始投稿管理密钥；已发布产品的修改需审核。产品网址不可修改。仅提交需要更新的字段，截图可设为 null 删除。",
        "security": [
          {
            "managementKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "summary": {
                    "type": "string",
                    "minLength": 4,
                    "maxLength": 120
                  },
                  "description": {
                    "type": "string",
                    "minLength": 20,
                    "maxLength": 10000
                  },
                  "category": {
                    "type": "string",
                    "enum": [
                      "games",
                      "interactive",
                      "quizzes",
                      "productivity",
                      "coding",
                      "automation",
                      "agents",
                      "utilities",
                      "information",
                      "showcase",
                      "data",
                      "models",
                      "research",
                      "learning",
                      "writing",
                      "design",
                      "creation",
                      "audio",
                      "video",
                      "podcasts",
                      "events",
                      "social",
                      "collaboration",
                      "other"
                    ],
                    "default": "other"
                  },
                  "features": {
                    "type": "array",
                    "maxItems": 6,
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 40
                    }
                  },
                  "source": {
                    "type": "string",
                    "format": "uri",
                    "maxLength": 2048
                  },
                  "contact": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "icon": {
                    "type": "string",
                    "description": "必填，PNG/JPEG/WebP 的 base64 data URL，解码后不超过 2 MiB。"
                  },
                  "screenshot": {
                    "anyOf": [
                      {
                        "type": "string",
                        "description": "选填，一张界面截图，PNG/JPEG/WebP 的 base64 data URL，解码后不超过 2 MiB。"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "minProperties": 1,
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "待审稿已更新"
          },
          "202": {
            "description": "已提交修改申请，返回新的查询凭据"
          },
          "404": {
            "description": "不存在或管理密钥不正确"
          },
          "409": {
            "description": "当前无法修改或已有申请待审"
          },
          "422": {
            "description": "字段错误"
          }
        }
      }
    },
    "/catalog.json": {
      "get": {
        "operationId": "readCatalog",
        "summary": "读取所有已发布产品",
        "responses": {
          "200": {
            "description": "公开产品目录"
          }
        }
      }
    },
    "/categories.json": {
      "get": {
        "operationId": "readCategories",
        "summary": "读取大类、投稿细分类与真实收录数",
        "responses": {
          "200": {
            "description": "groups 为浏览大类，categories 为投稿 category 可用值"
          }
        }
      }
    }
  }
}