{
  "openapi": "3.0.3",
  "info": {
    "title": "山啸赛事 API",
    "version": "1.0",
    "description": "按赛事主办方提供的租户域名调用。公开成绩可免费读取，赛事管理需要本租户管理员登录授权并开通赛事服务。"
  },
  "servers": [
    {
      "url": "https://{tenant}.montshock.com",
      "variables": {
        "tenant": {
          "default": "montshock",
          "description": "主办方分配的租户子域名"
        }
      }
    }
  ],
  "tags": [
    {
      "name": "公开成绩"
    },
    {
      "name": "租户赛事管理"
    }
  ],
  "paths": {
    "/v1/api/public/race/events/{event_id}/results": {
      "get": {
        "operationId": "getPublicRaceResults",
        "tags": [
          "公开成绩"
        ],
        "summary": "免费读取一场赛事已发布的正式成绩",
        "description": "无需登录或 API 密钥。赛事 ID 由主办方提供。各项目、阶段分别排名，未产生有效名次的记录没有 rank 和 time_ms。返回号码牌，不包含姓名、联系方式、证件号、照片和订单号。",
        "security": [],
        "parameters": [
          {
            "in": "path",
            "name": "event_id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "已发布成绩，list 可以为空",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "enum": [
                        200
                      ]
                    },
                    "msg": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "event_id": {
                          "type": "integer",
                          "format": "int64"
                        },
                        "list": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Result"
                          }
                        }
                      },
                      "required": [
                        "event_id",
                        "list"
                      ]
                    }
                  },
                  "required": [
                    "code",
                    "msg",
                    "data"
                  ],
                  "example": {
                    "code": 200,
                    "msg": "success",
                    "data": {
                      "event_id": 123,
                      "list": [
                        {
                          "project_id": "dh",
                          "stage_id": "final",
                          "bib": "018",
                          "status": "finished",
                          "rank": 1,
                          "time_ms": 123456
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "403": {
            "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"
                }
              }
            }
          }
        }
      }
    },
    "/v1/api/admin/race/events": {
      "get": {
        "operationId": "listTenantRaceEvents",
        "tags": [
          "租户赛事管理"
        ],
        "summary": "查询当前租户的赛事列表",
        "description": "使用赛事所属租户域名及有管理权限的有效登录凭证。配置与运营状态仅供获授权的租户服务端使用。",
        "security": [
          {
            "TenantBearer": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "configuring",
                "preparing"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "租户赛事分页结果",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "enum": [
                        200
                      ]
                    },
                    "msg": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "list": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/TenantEvent"
                          }
                        },
                        "page": {
                          "type": "integer"
                        },
                        "page_size": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        },
                        "serverTime": {
                          "type": "string",
                          "format": "date-time"
                        }
                      },
                      "required": [
                        "list",
                        "page",
                        "page_size",
                        "total",
                        "serverTime"
                      ]
                    }
                  },
                  "required": [
                    "code",
                    "msg",
                    "data"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "状态值无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "未登录或凭证失效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "缺少管理权限或服务权限",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "读取失败",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "TenantBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "租户后台授权的管理员登录凭证。"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          },
          "msg": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "msg"
        ]
      },
      "Result": {
        "type": "object",
        "properties": {
          "project_id": {
            "type": "string"
          },
          "stage_id": {
            "type": "string"
          },
          "bib": {
            "type": "string",
            "description": "号码牌，保留前导零"
          },
          "status": {
            "type": "string",
            "description": "finished、dns、dnf、dsq 等"
          },
          "rank": {
            "type": "integer",
            "minimum": 1,
            "description": "有有效名次时返回"
          },
          "time_ms": {
            "type": "integer",
            "format": "int64",
            "description": "有效成绩的计分用时，单位毫秒"
          }
        },
        "required": [
          "project_id",
          "stage_id",
          "bib",
          "status"
        ]
      },
      "TenantEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "version": {
            "type": "integer"
          },
          "step": {
            "type": "integer"
          },
          "status": {
            "type": "string"
          },
          "config": {
            "type": "object",
            "properties": {
              "basic": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "registrationOpen": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
