openapi: 3.1.0 info: title: anontopic API version: 0.1.0 description: | 匿名トピックチャットサービスの HTTP API。 利用者は会員登録を持たず、匿名のセッショントークンで識別する。トークンは `POST /api/session` が HttpOnly Cookie として発行し、以降のリクエストは ブラウザが自動で送る。方式の背景は docs/adr/0005-anonymous-session-tokens-in-redis.md にある。 servers: - url: http://localhost:8080 description: ローカル(make up で起動する api サービス) tags: - name: health description: プロセスと依存サービスの状態 - name: session description: 匿名セッションの発行と失効 - name: matching description: 待機キューとルームの割当 - name: chat description: ルーム内のリアルタイム通信 - name: topic description: トピックの一覧と管理 - name: report description: 会話の通報、権利侵害の申し立て、およびその確認と対応 paths: /healthz: get: tags: [health] operationId: getHealth summary: プロセスが生きているかを返す security: [] description: | PostgreSQL と Redis には触れない。コンテナのヘルスチェックとロードバランサが、 プロセスを再起動すべきかの判断に使う。 responses: "200": description: プロセスは動作している content: application/json: schema: $ref: "#/components/schemas/Health" /readyz: get: tags: [health] operationId: getReadiness summary: 依存するデータストアに接続できるかを返す security: [] responses: "200": description: PostgreSQL と Redis の両方に接続できる content: application/json: schema: $ref: "#/components/schemas/Readiness" "503": description: どちらかに接続できない。失敗した接続先にエラー内容が入る content: application/json: schema: $ref: "#/components/schemas/Readiness" /api/session: post: tags: [session] operationId: issueSession summary: セッションを発行する、または有効なセッションを延長する description: | 有効なセッション Cookie を持たないリクエストには新しいトークンを発行する。 すでに有効なセッションを持つ場合はトークンを作り直さず、無操作の期限だけを延長する。 トークンはレスポンスボディには含めず、Set-Cookie でのみ返す。 あわせて端末IDを`anontopic_device`(HttpOnly、1 年)で返す。リクエストが 端末IDを持っていればそれを延長し、持っていなければ新しく発行する。端末IDは セッションより長く残り、`banned_identifiers`の `device_fingerprint`として 段階的制裁の対象になる。理由は [ADR-0025](adr/0025-escalate-sanctions-on-the-device-id-and-leave-address-bans-to-operators.md) にある。 ボディで、利用者が任意で答えた性別と年代を受け取る。ボディを付けると、セッションの 答えを置き換える(無い項目・null・空文字は未回答)。ボディを付けないと、有効な セッションの答えはそのまま残る。答えは会話の参加者の記録に残すだけで、マッチングにも 相手への表示にも使わない。理由は [ADR-0044](adr/0044-record-the-gender-and-age-band-a-user-chose-to-give-without-matching-on-them.md) にある。 security: - {} - sessionCookie: [] requestBody: required: false content: application/json: schema: $ref: "#/components/schemas/SessionAttributes" responses: "201": description: 新しいセッションを発行した headers: Set-Cookie: description: セッショントークン schema: type: string examples: - anontopic_session=SJKsX5FJzjvav6ZnhCUBzUa73VYgZwtxB8n3viIJdIg; Path=/; Max-Age=86400; HttpOnly; Secure; SameSite=Lax - anontopic_device=q2m3Lr0Q4v1Kx8b6tZyWcN5aHfUeJ7sD9gPiRo0lVkE; Path=/; Max-Age=31536000; HttpOnly; Secure; SameSite=Lax content: application/json: schema: $ref: "#/components/schemas/Session" "200": description: 受け取ったセッションが有効だったため、期限を延長した headers: Set-Cookie: description: 同じトークンで有効期限を更新する schema: type: string content: application/json: schema: $ref: "#/components/schemas/Session" "400": description: 性別か年代に受け付けない値が入っている。セッションは発行も更新もしない "500": $ref: "#/components/responses/InternalServerError" delete: tags: [session] operationId: revokeSession summary: セッションを失効させる description: | 明示的な離脱。Redis からセッションを削除し、Cookie を破棄させる。 有効なセッションを持たないリクエストも同じ結果になるため 204 を返す。 security: - {} - sessionCookie: [] responses: "204": description: 失効した、または失効させるものが無かった headers: Set-Cookie: description: Max-Age=0 でクライアントから Cookie を消す schema: type: string "500": $ref: "#/components/responses/InternalServerError" /api/matching: post: tags: [matching] operationId: joinMatching summary: 待機キューに入り、揃っていればルームを成立させる description: | トピックとルーム種別で分かれた待機キューに入る。キューに必要な人数が揃っていれば その場で会話を成立させ、揃っていなければ待機のまま返す。 1 人が同時に入れるキューは 1 つで、成立したルームを持っている間は入り直せない。 同じキューへの再送は、すでに確保している順番をそのまま保つ。 3 人ルームは 3 人揃うのを待つが、先頭の利用者が `MATCHING_FALLBACK_AFTER` (既定 60 秒)を超えて待っている場合は 2 人で成立する。このとき返る `room_type` は 2 になる。理由は docs/adr/0009-fall-back-to-a-two-person-room.md にある。 BAN された識別子はキューに入れず 403 を返す。 同じ IP ハッシュからの要求は `CAPACITY_MATCH_BURST`(既定 3 回)まで続けて受け付け、 使い切ったあとは `CAPACITY_MATCH_INTERVAL`(既定 10 秒)に 1 回ずつ回復する。 レートを超えた要求はキューに入れず 429 を返す。理由は [ADR-0013](adr/0013-cap-connections-with-leases-in-redis.md) にある。 security: - sessionCookie: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/MatchingJoin" responses: "200": description: ルームが成立した content: application/json: schema: $ref: "#/components/schemas/MatchingState" "202": description: キューに入った。まだ人数が揃っていない content: application/json: schema: $ref: "#/components/schemas/MatchingState" "400": description: リクエストボディが不正、ルーム種別が 2 でも 3 でもない、または選べないトピック content: text/plain: schema: type: string examples: - unknown topic "401": $ref: "#/components/responses/SessionUnauthorized" "403": description: | IP ハッシュまたは端末 ID に一時停止か恒久停止がかかっている。 一時停止は `banned_until` を過ぎると自動で解ける content: text/plain: schema: type: string examples: - forbidden "409": description: 別のキューで待機中、またはすでにルームを持っている content: text/plain: schema: type: string examples: - already waiting in another queue "429": description: マッチングを要求するレートを超えた headers: Retry-After: description: | 次に要求してよいまでの秒数。`CAPACITY_MATCH_INTERVAL` を切り上げた値になる schema: type: integer examples: - 10 content: text/plain: schema: type: string examples: - asking to be matched too often "500": $ref: "#/components/responses/InternalServerError" get: tags: [matching] operationId: getMatchingState summary: 待機の状態を返す description: | 待機中のクライアントは、ルームが成立するまでこれを繰り返し呼ぶ。 呼び出しはルームの成立判定も兼ねるため、3 人ルームの 2 人へのフォールバックは 待っている本人のこの要求で起きる。 security: - sessionCookie: [] responses: "200": description: 待機中、またはルームが成立している content: application/json: schema: $ref: "#/components/schemas/MatchingState" "401": $ref: "#/components/responses/SessionUnauthorized" "404": description: どのキューでも待っておらず、ルームも持っていない content: text/plain: schema: type: string examples: - not waiting "500": $ref: "#/components/responses/InternalServerError" delete: tags: [matching] operationId: leaveMatching summary: 待機をやめる description: | キューから抜け、成立したルームの割り当ても手放す。どちらも持っていない リクエストは同じ結果になるため 204 を返す。 会話そのものはここでは終わらない。参加者が接続を切ってから `CHAT_REJOIN_GRACE` を過ぎたときに終わるため、この呼び出しの後も猶予の間は 同じ会話に戻れる。理由は [ADR-0011](adr/0011-end-a-conversation-after-a-rejoin-grace.md) にある。 security: - sessionCookie: [] responses: "204": description: 待機をやめた、またはやめるものが無かった "401": $ref: "#/components/responses/SessionUnauthorized" "500": $ref: "#/components/responses/InternalServerError" /api/matching/queues: get: tags: [matching] operationId: listMatchingQueues summary: キューごとに待っている人がいるかどうかを返す description: | 有効なトピックのキュー(トピックとルーム種別の組)ごとに、待っている人がいるかを 真偽値で返す。人数は返さない。待機が `MATCHING_WAIT_TTL` を過ぎた利用者は数えない。 トピック選択画面がセッションを用意する前に呼ぶため、認証は要らない。 答えは各サーバーが `MATCHING_STATUS_TTL`(既定 5 秒)の間使い回すため、 キューの変化が反映されるまでその分遅れる。理由は [ADR-0048](adr/0048-show-users-whether-anyone-waits-in-a-queue-without-the-count.md) にある。 responses: "200": description: 有効なトピックのキューの一覧。トピックの表示順に、2 人ルーム・3 人ルームの順で並ぶ headers: Cache-Control: description: | `no-store`。答えはサーバーが `MATCHING_STATUS_TTL` の間だけ使い回すもので、 ブラウザや途中のプロキシ・CDN にそれより長く残させない schema: type: string examples: - no-store content: application/json: schema: $ref: "#/components/schemas/MatchingQueueList" "500": $ref: "#/components/responses/InternalServerError" /ws/rooms/{roomID}: get: tags: [chat] operationId: connectRoomSocket summary: ルームの WebSocket 接続を確立する description: | マッチングで成立した会話に接続する。`roomID` は `/api/matching` が返した会話 ID。 サービス全体が `CAPACITY_MAX_CONNECTIONS`(既定 1,000)本の接続を持っている間は、 セッションを検証する前に 503 で拒否する。1 つの IP ハッシュが `CAPACITY_MAX_CONNECTIONS_PER_IP`(既定 5)本を持っている場合は 429 を返す。 どちらも `Retry-After` を付ける。理由は [ADR-0013](adr/0013-cap-connections-with-leases-in-redis.md) にある。 Origin ヘッダが `APP_ALLOWED_ORIGINS` にも自ホストにも一致しない場合は、 セッションを検証する前に 403 で拒否する。検証はセッションの寿命を延ばすため、 他サイトのページが他人のセッションを延命できないようにしている。 会話の参加者でない場合と、会話が存在しない場合は区別せず 403 を返す。 IP ハッシュまたは端末 ID に一時停止か恒久停止がかかっている場合も 403 を返す。 接続後はテキストフレームで JSON をやり取りする。クライアントが送るのは メッセージのみで、サーバーからは以下の `type` が届く。サーバーは 30 秒ごとに ping を送るため、ブラウザ以外のクライアントは pong を返す必要がある。 各フレームのスキーマは [asyncapi.yaml](asyncapi.yaml) にある。 | `type` | 内容 | | --- | --- | | `joined` | 接続した本人への挨拶。`conversation` / `participant`(自分の番号)/ `present`(接続中の参加者の番号)が入る | | `participant_joined` | 誰かが入室した。自分の入室も届く | | `participant_left` | 誰かが退出した | | `message` | メッセージ。`participant`(送信者の番号)/ `body` / `sent_at` が入る。送信者にも同じものが届く | | `ended` | 会話が終了した。`reason` は `conversations.end_reason` の値。これを最後にサーバーが接続を閉じる。`reason` が `banned` のものは BAN された本人にだけ届き、会話は他の参加者の間で続く | | `warning` | 運営からの警告。本人にだけ届く。NG ワードでのブロックが続いたとき、または接続していない間に警告が出ていたときに入室直後に届く | | `error` | 送信者だけに返る。`code` は `invalid_frame` / `empty_body` / `too_long` / `blocked` / `rate_limited` / `unavailable` | 参加者は会話ごとの番号(1 起点)で表す。セッショントークンは他の参加者に渡らない。 本文が 2000 文字を超えるメッセージは `too_long` で拒否する。 送信は `CAPACITY_MESSAGE_BURST`(既定 5 通)まで続けて受け付け、使い切ったあとは `CAPACITY_MESSAGE_INTERVAL`(既定 1 秒)に 1 通ずつ回復する。超えた送信は `rate_limited` で拒否し、部屋には配信しない。 メッセージは配信された後にまとめて保存される。`sent_at` はサーバーが受け付けた 時刻で、保存される時刻と同じものになる。理由は [ADR-0012](adr/0012-buffer-message-writes-into-batched-inserts.md) にある。 NG ワードでブロックされた送信は端末 ID ごとに数え、`SANCTION_BLOCKED_THRESHOLD` (既定 5 通)に達するたびに警告 → 一時停止(`SANCTION_SUSPENSION`、既定 24 時間)→ 恒久停止と段階を進める。一時停止以上になった接続には `ended`(`reason: banned`)を 送って閉じる。 接続中の参加者が 1 人以下のまま `CHAT_REJOIN_GRACE` を過ぎると、会話は `user_left` で終了する。切断してから猶予の間は同じ会話に再接続でき、 参加者が増えることはない。理由は [ADR-0011](adr/0011-end-a-conversation-after-a-rejoin-grace.md) にある。 security: - sessionCookie: [] parameters: - name: roomID in: path required: true description: 接続先の会話 ID schema: type: string format: uuid responses: "101": description: WebSocket に切り替えた "401": description: 有効なセッションが無い content: text/plain: schema: type: string examples: - unauthorized "403": description: 許可されていない Origin からの接続、参加者でない会話への接続、または BAN された識別子からの接続 content: text/plain: schema: type: string examples: - forbidden "410": description: 会話が既に終了している content: text/plain: schema: type: string examples: - the conversation has ended "429": description: 同じ IP ハッシュが持てる接続数を超えた headers: Retry-After: description: 次に接続してよいまでの秒数 schema: type: integer examples: - 10 content: text/plain: schema: type: string examples: - too many connections "500": $ref: "#/components/responses/InternalServerError" "503": description: サービス全体が持てる接続数に達している headers: Retry-After: description: 次に接続してよいまでの秒数 schema: type: integer examples: - 10 content: text/plain: schema: type: string examples: - the service is busy /api/topics: get: tags: [topic] operationId: listTopics summary: 選択できるトピックの一覧を返す security: [] description: | `is_active = true` のトピックだけを ID 昇順で返す。トピック選択画面は、 この結果だけで描画できる。 内容の更新頻度が低いため、API サーバーはプロセス内に一定時間キャッシュする (既定 5 分、`TOPIC_CACHE_TTL` で変更可能)。管理 API で変更した内容が 全サーバーに反映されるまで、最大でその時間かかる。理由は docs/adr/0006-cache-the-topic-list-in-process.md にある。 responses: "200": description: 有効なトピックの一覧 content: application/json: schema: $ref: "#/components/schemas/TopicList" "500": $ref: "#/components/responses/InternalServerError" /api/admin/topics: get: tags: [topic] operationId: listAllTopics summary: 無効なものを含む全トピックを返す security: - adminToken: [] responses: "200": description: 全トピックの一覧 content: application/json: schema: $ref: "#/components/schemas/AdminTopicList" "401": $ref: "#/components/responses/AdminUnauthorized" "500": $ref: "#/components/responses/InternalServerError" post: tags: [topic] operationId: createTopic summary: トピックを追加する description: 追加したトピックは有効な状態で作られ、選択画面に出る。 security: - adminToken: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/TopicCreate" responses: "201": description: 追加した content: application/json: schema: $ref: "#/components/schemas/AdminTopic" "400": $ref: "#/components/responses/InvalidTopicRequest" "401": $ref: "#/components/responses/AdminUnauthorized" "500": $ref: "#/components/responses/InternalServerError" /api/admin/topics/presence: get: tags: [topic] operationId: countTopicPresence summary: トピックごとに、いま何人いるかを返す description: | 無効なトピックも含め、全トピックについて返す。無効にしたトピックでも、 すでに始まっている会話は続くため。 `connected` はそのトピックの会話に WebSocket で接続している参加者の数、 `waiting` はそのトピックのキューで待っている利用者の数(2 人部屋と 3 人部屋の合計)。 どちらも Redis にある接続と待機の記録から数える。接続を持つサーバーが止まった場合、 その参加者は接続の記録が切れる(最大 30 秒)まで数に残る。 security: - adminToken: [] responses: "200": description: トピックごとの人数 content: application/json: schema: $ref: "#/components/schemas/TopicPresenceList" "401": $ref: "#/components/responses/AdminUnauthorized" "500": $ref: "#/components/responses/InternalServerError" /api/admin/topics/{id}: parameters: - name: id in: path required: true description: トピックID schema: type: integer minimum: 1 patch: tags: [topic] operationId: updateTopic summary: トピックの名前や有効フラグを変える description: | 省略したフィールドは変更しない。`is_active` を false にすると選択画面から 消えるが、そのトピックを参照している会話はそのまま残る。 security: - adminToken: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/TopicUpdate" responses: "200": description: 変更後のトピック content: application/json: schema: $ref: "#/components/schemas/AdminTopic" "400": $ref: "#/components/responses/InvalidTopicRequest" "401": $ref: "#/components/responses/AdminUnauthorized" "404": $ref: "#/components/responses/TopicNotFound" "500": $ref: "#/components/responses/InternalServerError" delete: tags: [topic] operationId: deleteTopic summary: トピックを削除する description: | 会話から参照されているトピックは削除できない。その場合は 409 を返すため、 選択画面から消すには `is_active` を false にする。 security: - adminToken: [] responses: "204": description: 削除した "400": description: トピックIDが数値でない content: text/plain: schema: type: string examples: - invalid topic id "401": $ref: "#/components/responses/AdminUnauthorized" "404": $ref: "#/components/responses/TopicNotFound" "409": description: 会話から参照されているため削除できない content: text/plain: schema: type: string examples: - topic is referenced by conversations "500": $ref: "#/components/responses/InternalServerError" /api/reports: post: tags: [report] operationId: submitReport summary: 会話を通報する description: | 参加した会話を通報する。通報できるのはその会話の参加者だけで、参加していない 会話と存在しない会話は区別せず 403 を返す。会話が終わった後も通報できる。 参加者は互いに匿名で、部屋の中の参加者番号は部屋の外では意味を持たないため、 通報の対象は相手ではなく会話そのものになる。通報者が選ぶのは、要件定義書の 禁止行為に沿った `reason` の分類だけ。 同じ会話を同じ通報者が繰り返し通報しても記録は増えない。会話に付く通報の数を、 ボタンが押された回数ではなく通報した参加者の人数にするため。 受け付けた会話は `is_flagged` を立てて保持期間の削除から外し、通報者以外が送った メッセージの `moderation_flag` を 2(通報あり)にする。進行中の会話は `end_reason = reported` で終わり、参加者全員に `ended` イベントが届く。 どの処理も繰り返して安全なため、500 が返った通報は送り直せば完了する。理由は docs/adr/0021-end-and-keep-a-conversation-once-it-is-reported.md にある。 security: - sessionCookie: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ReportSubmission" responses: "204": description: 通報を受け付けた "400": description: リクエストボディが不正、または `reason` が分類にない content: text/plain: schema: type: string examples: - unknown reason "401": $ref: "#/components/responses/SessionUnauthorized" "403": description: 参加していない会話への通報 content: text/plain: schema: type: string examples: - forbidden "500": $ref: "#/components/responses/InternalServerError" /api/claims: post: tags: [report] operationId: submitClaim summary: 権利侵害の申し立てを送る description: | 会話の参加者に限らず、誰でも送れる。セッションは要らない。会話は参加者どうしでしか 見えず、申立人は会話 ID を知り得ないため、どの会話かは `details` に書いてもらい、 運営が探して確認する。 セッションを要求しない代わりに、接続元の IP ハッシュごとにレートを制限する (`CAPACITY_CLAIM_BURST` 件まで続けて送れ、以降は `CAPACITY_CLAIM_INTERVAL` に 1 件ずつ回復する)。理由は docs/adr/0022-take-rights-infringement-claims-from-anyone.md にある。 security: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ClaimSubmission" responses: "204": description: 申し立てを受け付けた "400": description: リクエストボディが不正、または項目が空・長すぎる・形式が違う content: text/plain: schema: type: string examples: - "report: invalid claim: email" "429": description: 同じ IP ハッシュから短時間に送られすぎた headers: Retry-After: description: 次に送れるまでの秒数 schema: type: integer content: text/plain: schema: type: string examples: - too many claims "500": $ref: "#/components/responses/InternalServerError" /api/admin/reports: get: tags: [report] operationId: listReports summary: 通報を新しい順に返す description: | 通報者のセッショントークンは返さない。次のページは、受け取った最後の `id` を `before` に渡して読む。 security: - adminToken: [] parameters: - $ref: "#/components/parameters/StatusFilter" - name: conversation_id in: query description: この会話に付いた通報だけを返す schema: type: string format: uuid - $ref: "#/components/parameters/BeforeID" - $ref: "#/components/parameters/ListLimit" responses: "200": description: 通報の一覧 content: application/json: schema: $ref: "#/components/schemas/ReportList" "400": $ref: "#/components/responses/InvalidListQuery" "401": $ref: "#/components/responses/AdminUnauthorized" "500": $ref: "#/components/responses/InternalServerError" /api/admin/reports/{id}: parameters: - $ref: "#/components/parameters/SubmissionID" get: tags: [report] operationId: reviewReport summary: 通報 1 件と、対象の会話ログを返す description: | 参加者はルーム内の番号(1 起点)で示し、セッショントークンは返さない。 理由は docs/adr/0023-review-reports-through-the-admin-api.md にある。 security: - adminToken: [] responses: "200": description: 通報と会話ログ content: application/json: schema: $ref: "#/components/schemas/ReportReview" "400": $ref: "#/components/responses/InvalidSubmissionID" "401": $ref: "#/components/responses/AdminUnauthorized" "404": $ref: "#/components/responses/SubmissionNotFound" "500": $ref: "#/components/responses/InternalServerError" patch: tags: [report] operationId: updateReportStatus summary: 通報の対応ステータスを変える description: どのステータスからどのステータスへも変えられる。 security: - adminToken: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/StatusUpdate" responses: "200": description: 変更後の通報 content: application/json: schema: $ref: "#/components/schemas/Report" "400": $ref: "#/components/responses/InvalidStatusUpdate" "401": $ref: "#/components/responses/AdminUnauthorized" "404": $ref: "#/components/responses/SubmissionNotFound" "500": $ref: "#/components/responses/InternalServerError" /api/admin/claims: get: tags: [report] operationId: listClaims summary: 権利侵害の申し立てを新しい順に返す security: - adminToken: [] parameters: - $ref: "#/components/parameters/StatusFilter" - $ref: "#/components/parameters/BeforeID" - $ref: "#/components/parameters/ListLimit" responses: "200": description: 申し立ての一覧 content: application/json: schema: $ref: "#/components/schemas/ClaimList" "400": $ref: "#/components/responses/InvalidListQuery" "401": $ref: "#/components/responses/AdminUnauthorized" "500": $ref: "#/components/responses/InternalServerError" /api/admin/claims/{id}: parameters: - $ref: "#/components/parameters/SubmissionID" patch: tags: [report] operationId: updateClaimStatus summary: 申し立ての対応ステータスを変える security: - adminToken: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/StatusUpdate" responses: "200": description: 変更後の申し立て content: application/json: schema: $ref: "#/components/schemas/Claim" "400": $ref: "#/components/responses/InvalidStatusUpdate" "401": $ref: "#/components/responses/AdminUnauthorized" "404": $ref: "#/components/responses/SubmissionNotFound" "500": $ref: "#/components/responses/InternalServerError" /api/admin/bans: get: tags: [report] operationId: listBans summary: 制裁を新しい順に返す description: | 警告・一時停止・恒久停止のすべてを返す。`active=true`を付けると、 いま効いている一時停止と恒久停止だけを返す。解除した制裁も記録として残る。 security: - adminToken: [] parameters: - name: active in: query description: true なら、いま効いている一時停止と恒久停止だけを返す schema: type: boolean - $ref: "#/components/parameters/BeforeID" - $ref: "#/components/parameters/ListLimit" responses: "200": description: 制裁の一覧 content: application/json: schema: $ref: "#/components/schemas/BanList" "400": description: "`active` / `before` / `limit` が読めない" content: text/plain: schema: type: string examples: - invalid active "401": $ref: "#/components/responses/AdminUnauthorized" "500": $ref: "#/components/responses/InternalServerError" post: tags: [report] operationId: imposeBan summary: 会話の参加者に制裁をかける description: | 参加者は会話の中の番号(通報の確認画面の `participant`)で指す。識別子そのものは 運営に渡さないため、どちらの識別子にかけるかを `identifier_type` で選ぶ。 `ip_hash` は同じ回線(モバイル回線のゲートウェイ、学校など)の全員に効く。 自動の制裁は `device_fingerprint` にしかかけないため、回線ごと止める判断は 会話を読んだ運営が行う。理由は [ADR-0025](adr/0025-escalate-sanctions-on-the-device-id-and-leave-address-bans-to-operators.md) にある。 security: - adminToken: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/BanCreate" responses: "201": description: かけた制裁 content: application/json: schema: $ref: "#/components/schemas/Ban" "400": description: | リクエストボディが不正、会話 ID が読めない、参加者番号が会話に無い、 または `identifier_type` / `sanction` / `duration_hours` / `reason` が不正 content: text/plain: schema: type: string examples: - unknown participant "401": $ref: "#/components/responses/AdminUnauthorized" "409": description: 参加者にその種類の識別子が記録されていない content: text/plain: schema: type: string examples: - no identifier of that type is recorded for the participant "500": $ref: "#/components/responses/InternalServerError" /api/admin/bans/{id}: parameters: - name: id in: path required: true description: 制裁ID schema: type: integer minimum: 1 delete: tags: [report] operationId: liftBan summary: 制裁を解除する description: | 行は消さずに `lifted_at` を記録する。解除した制裁は効かなくなり、 次の自動制裁の段階を決める数にも入らない。 security: - adminToken: [] responses: "200": description: 解除した制裁 content: application/json: schema: $ref: "#/components/schemas/Ban" "400": $ref: "#/components/responses/InvalidSubmissionID" "401": $ref: "#/components/responses/AdminUnauthorized" "404": description: その ID の制裁が無い content: text/plain: schema: type: string examples: - not found "409": description: すでに解除されている content: text/plain: schema: type: string examples: - already lifted "500": $ref: "#/components/responses/InternalServerError" components: parameters: SubmissionID: name: id in: path required: true description: 通報ID または申し立てID schema: type: integer minimum: 1 StatusFilter: name: status in: query description: この対応ステータスのものだけを返す schema: $ref: "#/components/schemas/ReviewStatus" BeforeID: name: before in: query description: この ID より古いものだけを返す。前のページの最後の `id` を渡す schema: type: integer minimum: 1 ListLimit: name: limit in: query description: 返す件数の上限。省略時は 50、200 を超える値は 200 として扱う schema: type: integer minimum: 1 securitySchemes: adminToken: type: http scheme: bearer description: | `ADMIN_API_TOKEN` に設定した秘密。未設定の環境では管理エンドポイント自体を 登録しないため、そのパスは 404 を返す。方式の背景は docs/adr/0007-guard-the-admin-api-with-a-static-bearer-token.md にある。 sessionCookie: type: apiKey in: cookie name: anontopic_session description: | POST /api/session が発行する HttpOnly Cookie。ブラウザが自動で送るため、 フロントエンドのコードがトークンを読むことはない。 schemas: Session: type: object description: | セッションの有効期限。トークン自体は Cookie でのみ渡すため、ここには含めない。 required: [expires_at] properties: expires_at: type: string format: date-time description: これ以降アクセスが無ければセッションが失効する時刻 examples: - "2026-08-22T12:24:55.302874Z" SessionAttributes: type: object additionalProperties: false description: 利用者が任意で答えた性別と年代。マッチングにも相手への表示にも使わない properties: gender: type: [string, "null"] enum: [female, male, other, "", null] description: 性別。null か空文字は未回答 age_band: type: [string, "null"] enum: [under_18, "18_19", 20s, 30s, 40s, 50s, 60_plus, "", null] description: 年代。null か空文字は未回答 examples: - gender: female age_band: 20s Topic: type: object description: 選択画面が 1 件を描画するのに必要な情報。 required: [id, name] properties: id: type: integer examples: - 1 name: type: string maxLength: 100 examples: - 雑談 TopicList: type: object required: [topics] properties: topics: type: array items: $ref: "#/components/schemas/Topic" AdminTopic: type: object description: 管理操作で扱う 1 件。 required: [id, name, is_active, created_at] properties: id: type: integer examples: - 1 name: type: string maxLength: 100 examples: - 雑談 is_active: type: boolean description: false のトピックは GET /api/topics に出ない examples: - true created_at: type: string format: date-time examples: - "2026-08-26T09:12:03.482913Z" TopicPresence: type: object description: 1 つのトピックにいる人数。 required: [id, connected, waiting] properties: id: type: integer description: トピックID examples: - 1 connected: type: integer minimum: 0 description: このトピックの会話に接続している参加者の数 examples: - 5 waiting: type: integer minimum: 0 description: このトピックのキューで待っている利用者の数 examples: - 1 TopicPresenceList: type: object required: [counted_at, topics] properties: counted_at: type: string format: date-time description: 数えた時刻 examples: - "2026-10-28T04:12:03.482Z" topics: type: array items: $ref: "#/components/schemas/TopicPresence" AdminTopicList: type: object required: [topics] properties: topics: type: array items: $ref: "#/components/schemas/AdminTopic" TopicCreate: type: object required: [name] properties: name: type: string description: 前後の空白は取り除いて保存する。空文字と 100 文字超は 400 maxLength: 100 examples: - ゲーム TopicUpdate: type: object description: 省略したフィールドは変更しない。 properties: name: type: string maxLength: 100 examples: - ゲーム is_active: type: boolean examples: - false MatchingJoin: type: object description: 入りたい待機キュー。 required: [topic_id, room_type] properties: topic_id: type: integer description: GET /api/topics が返すトピックの ID minimum: 1 examples: - 1 room_type: type: integer description: ルーム種別。2 は 2 人ルーム、3 は 3 人ルーム enum: [2, 3] examples: - 3 ReportSubmission: type: object description: 通報する会話と、その分類。 required: [conversation_id, reason] properties: conversation_id: type: string format: uuid description: 通報する会話の ID examples: - 7f1fca8f-ca30-40c7-a752-ef5ffa6bac2a reason: $ref: "#/components/schemas/ReportReason" ReportReason: type: string description: | 通報の分類。`dating` は出会い・交際目的、`sexual` は性的な内容、`contact` は 連絡先の交換や外部への誘導、`harassment` は誹謗中傷・暴言・いやがらせ、 `spam` は宣伝、`other` はそれ以外。`dating` を分ける前に記録された `sexual` には 出会い目的の通報も含まれる(docs/adr/0024-split-dating-out-of-the-sexual-report-reason.md) enum: [dating, sexual, contact, harassment, spam, other] examples: - contact ReviewStatus: type: string description: | 対応ステータス。`open` は未確認、`reviewing` は確認中、`actioned` は対応済み、 `rejected` は対応不要と判断したもの enum: [open, reviewing, actioned, rejected] examples: - open StatusUpdate: type: object required: [status] properties: status: $ref: "#/components/schemas/ReviewStatus" Report: type: object description: 通報 1 件。通報者のセッショントークンは含めない。 required: [id, conversation_id, reason, status, created_at] properties: id: type: integer examples: - 12 conversation_id: type: string format: uuid examples: - 7f1fca8f-ca30-40c7-a752-ef5ffa6bac2a reason: $ref: "#/components/schemas/ReportReason" status: $ref: "#/components/schemas/ReviewStatus" created_at: type: string format: date-time examples: - "2026-09-21T06:28:47.837216Z" ReportList: type: object required: [reports] properties: reports: type: array items: $ref: "#/components/schemas/Report" ReportReview: type: object description: 通報 1 件と、対象の会話ログ。 required: [report, reporter, conversation, messages] properties: report: $ref: "#/components/schemas/Report" reporter: type: integer description: 通報者のルーム内の番号(1 起点) examples: - 1 conversation: type: object required: [id, topic_id, room_type, participants, started_at, ended_at, end_reason, is_flagged] properties: id: type: string format: uuid topic_id: type: integer room_type: type: integer enum: [2, 3] participants: type: integer description: 会話に割り当てられた参加者の数 started_at: type: string format: date-time ended_at: type: [string, "null"] format: date-time description: 進行中は null end_reason: type: [string, "null"] description: "`user_left` / `reported` など。進行中は null" examples: - reported is_flagged: type: boolean description: true の会話は保持期間を過ぎても削除しない messages: type: array description: 記録されたメッセージを古い順に。フィルタが配信を止めたものも含む items: type: object required: [participant, body, moderation_flag, created_at] properties: participant: type: integer description: 送信者のルーム内の番号(1 起点) examples: - 2 body: type: string examples: - LINEのID教えて moderation_flag: type: integer enum: [0, 1, 2] description: | 0 は問題なし、1 は NG ワードフィルタが判定したもの、2 は通報時点で記録済み だった、通報者以外の発言 examples: - 1 created_at: type: string format: date-time ClaimSubmission: type: object description: 権利侵害の申し立て。各項目は前後の空白を取り除いてから検査する。 required: [name, email, right, details] properties: name: type: string description: 申立人の氏名または名称 maxLength: 100 examples: - 山田 太郎 email: type: string format: email description: 対応の結果を連絡する宛先。表示名付きの形式は受け付けない maxLength: 254 examples: - taro@example.com right: $ref: "#/components/schemas/ClaimRight" details: type: string description: 侵害情報の内容、いつごろのどの会話か、侵害と考える理由 maxLength: 4000 examples: - 私の本名と勤務先が会話の中に書き込まれていたと知人から聞きました。 ClaimRight: type: string description: | 侵害されたと考える権利。`privacy` はプライバシー、`defamation` は名誉・信用、 `copyright` は著作権、`other` はそれ以外 enum: [privacy, defamation, copyright, other] examples: - privacy Claim: type: object description: 権利侵害の申し立て 1 件。 required: [id, name, email, right, details, status, created_at] properties: id: type: integer examples: - 3 name: type: string email: type: string format: email right: $ref: "#/components/schemas/ClaimRight" details: type: string status: $ref: "#/components/schemas/ReviewStatus" created_at: type: string format: date-time ClaimList: type: object required: [claims] properties: claims: type: array items: $ref: "#/components/schemas/Claim" BanCreate: type: object description: 運営が会話の参加者にかける制裁。 required: [conversation_id, participant, identifier_type, sanction] additionalProperties: false properties: conversation_id: type: string format: uuid participant: type: integer minimum: 1 description: 会話の中の参加者番号 identifier_type: $ref: "#/components/schemas/IdentifierType" sanction: $ref: "#/components/schemas/Sanction" duration_hours: type: integer minimum: 1 maximum: 8760 description: 一時停止の時間数。`suspension` では必須で、それ以外では指定しない reason: type: string maxLength: 100 description: 制裁の理由。運営の記録として残す Ban: type: object description: | 制裁 1 件。識別子そのものは運営にも返さない。 required: [id, identifier_type, sanction, source, reason, conversation_id, banned_until, created_at, lifted_at] properties: id: type: integer examples: - 12 identifier_type: $ref: "#/components/schemas/IdentifierType" sanction: $ref: "#/components/schemas/Sanction" source: type: string enum: [ng_word, report, operator] description: | 制裁のきっかけ。`ng_word` は NG ワードでのブロックの蓄積、 `report` は通報された会話の蓄積、`operator` は運営が管理 API からかけたもの reason: type: string description: 運営が書いた理由。自動の制裁では空 conversation_id: type: - string - "null" format: uuid description: 制裁のきっかけになった会話 banned_until: type: - string - "null" format: date-time description: 一時停止の終了日時。警告と恒久停止では null created_at: type: string format: date-time lifted_at: type: - string - "null" format: date-time description: 運営が解除した日時。解除されていなければ null BanList: type: object required: [bans] properties: bans: type: array items: $ref: "#/components/schemas/Ban" IdentifierType: type: string enum: [ip_hash, device_fingerprint] description: | `ip_hash` は接続元 IP の鍵付きハッシュで、同じ回線の全員に効く。 `device_fingerprint` はサーバーが Cookie で渡す端末 ID で、その端末にだけ効く Sanction: type: string enum: [warning, suspension, permanent] description: | 制裁の段階。`warning` はチャット画面に警告を出すだけで利用は止めない。 `suspension` は `banned_until` まで、`permanent` は無期限に接続とマッチングを拒否する MatchingQueueList: type: object required: [queues] properties: queues: type: array items: $ref: "#/components/schemas/MatchingQueueStatus" MatchingQueueStatus: type: object description: 1 つのキューに待っている人がいるかどうか required: [topic_id, room_type, waiting] properties: topic_id: type: integer examples: - 1 room_type: type: integer enum: [2, 3] examples: - 2 waiting: type: boolean description: このキューで待っている人が 1 人以上いれば true examples: - true MatchingState: type: object description: | 待機の状態。`state` が `waiting` の間は `waiting_since` と `waiting_until` が、 `matched` になると `conversation` が入る。 required: [state, topic_id, room_type] properties: state: type: string enum: [waiting, matched] examples: - waiting topic_id: type: integer examples: - 1 room_type: type: integer description: | 成立したルームの人数。3 人ルームで待っていても、フォールバックで成立した 場合は 2 になる enum: [2, 3] examples: - 2 waiting_since: type: string format: date-time description: 待機を始めた時刻。`state` が `waiting` のときに入る examples: - "2026-08-27T07:13:01.562Z" waiting_until: type: string format: date-time description: | 待機が打ち切られる時刻。`waiting_since` に `MATCHING_WAIT_TTL`(既定 21 分)を 足したもので、`state` が `waiting` のときに入る。過ぎると待機は終わり、 `GET /api/matching` は 404 を返す examples: - "2026-08-27T07:23:01.562Z" conversation: type: object description: 参加する会話。`state` が `matched` のときに入る required: [id, started_at] properties: id: type: string format: uuid description: WebSocket の接続先になる会話 ID examples: - 7f1fca8f-ca30-40c7-a752-ef5ffa6bac2a started_at: type: string format: date-time examples: - "2026-08-27T07:13:01.595Z" Health: type: object required: [status] properties: status: type: string examples: - ok Readiness: type: object required: [status, postgres, redis] properties: status: type: string description: すべて接続できれば ok、そうでなければ unavailable examples: - ok postgres: type: string description: 接続できれば ok、できなければエラー内容 examples: - ok redis: type: string examples: - ok responses: AdminUnauthorized: description: 管理トークンが無い、または一致しない content: text/plain: schema: type: string examples: - unauthorized SessionUnauthorized: description: 有効なセッションが無い content: text/plain: schema: type: string examples: - unauthorized InvalidTopicRequest: description: リクエストボディが不正、またはトピック名が空か長すぎる content: text/plain: schema: type: string examples: - invalid topic name TopicNotFound: description: そのIDのトピックが無い content: text/plain: schema: type: string examples: - topic not found InvalidListQuery: description: "`status` が一覧にない、または `before` / `limit` / `conversation_id` が読めない" content: text/plain: schema: type: string examples: - unknown status InvalidSubmissionID: description: ID が正の整数でない content: text/plain: schema: type: string examples: - invalid id InvalidStatusUpdate: description: ID かリクエストボディが不正、または `status` が一覧にない content: text/plain: schema: type: string examples: - unknown status SubmissionNotFound: description: その ID の通報または申し立てが無い content: text/plain: schema: type: string examples: - not found InternalServerError: description: サーバー側の想定外の失敗 content: text/plain: schema: type: string examples: - internal server error