Skip to content

feat: add Redoc API documentation#66

Merged
shimomo merged 1 commit intogh-pagesfrom
feature/add-openapi-docs
Aug 31, 2025
Merged

feat: add Redoc API documentation#66
shimomo merged 1 commit intogh-pagesfrom
feature/add-openapi-docs

Conversation

@shimomo
Copy link
Copy Markdown
Contributor

@shimomo shimomo commented Aug 31, 2025

試しに Redoc で API の仕様書を公開してみようと思います。

Summary by CodeRabbit

  • Documentation
    • Redoc を用いた API ドキュメントページ(docs/v2/index.html)を追加。タイトルを「Boatrace Open API for Programs」に設定。
    • OpenAPI v3.0.3 仕様(docs/v2/openapi.json)を追加。/programs/v2/today.json の 200/400/404/500 応答、プログラムおよびボート情報のスキーマと必須項目を明記。
    • 仕様には本番サーバー情報とデータ型(string/integer/number/date-time)を定義。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 31, 2025

Walkthrough

ドキュメント用の静的ページ docs/v2/index.html を新規追加し、Redoc で OpenAPI を表示。併せて docs/v2/openapi.json として OpenAPI v3.0.3 仕様(v2.0.0、/programs/v2/today.json のGETエンドポイント1本、スキーマ定義とエラーレスポンス含む)を新規追加。

Changes

Cohort / File(s) Summary of Changes
Docs v2 (Redoc UI & Spec)
docs/v2/index.html, docs/v2/openapi.json
Redoc を用いた API ドキュメント用 HTML を追加(CDNスクリプト読込、<redoc> で spec-url="openapi.json" を指定)。OpenAPI v3.0.3 仕様ファイルを追加(API v2.0.0、GET /programs/v2/today.json、200/400/404/500 レスポンス、プログラムおよびボート情報の詳細スキーマ定義)。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User Browser
  participant H as docs/v2/index.html
  participant R as Redoc (CDN)
  participant S as Server
  note over U,H: ページ読み込み
  U->>H: GET /docs/v2/index.html
  H-->>U: HTML (Redoc 初期化)
  U->>R: Load Redoc script
  note over R: Redoc 起動
  R->>S: GET /docs/v2/openapi.json
  S-->>R: 200 OpenAPI JSON
  R-->>U: API ドキュメントをレンダリング
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

ふわり跳ねて、ドキュメントの丘
Redocの風に耳がぴん
JSONの道は一本すっと
今日のレースを照らす月
ぱたぱた頁、にんじん色の夢
ぼくのAPI、波間にきらり 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/add-openapi-docs

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (8)
docs/v2/openapi.json (5)

1-13: グローバル security の方針を明示してください(公開APIなら security: [] を定義)

現状は security 未定義のため、ツール(Checkov: CKV_OPENAPI_4/5)が警告します。認証不要な公開APIである方針なら、明示的に security: [] を追加して意図を示すのが無難です。将来的に鍵やOAuth導入予定なら components.securitySchemes も併記を。

適用例(servers の直後に追加):

   "servers": [
     {
       "url": "https://boatraceopenapi.github.io",
       "description": "Production server"
     }
   ],
+  "security": [],

16-41: operationId・tags・例を追加してクライアント生成と可読性を向上

生成クライアントやドキュメントの品質向上のため、operationId/tags と 200 のサンプルを追加することを推奨します。

   "get": {
-    "summary": "GET /programs/v2/today.json",
-    "description": "GET operation for /programs/v2/today.json",
+    "operationId": "getProgramsToday",
+    "tags": ["Programs"],
+    "summary": "Get today's race programs",
+    "description": "今日の番組表(JSON)を取得します。",
     "parameters": [],
     "responses": {
       "200": {
         "description": "Successful response",
         "content": {
           "application/json": {
             "schema": {
               "$ref": "#/components/schemas/BoatraceOpenAPI"
-            }
+            },
+            "examples": {
+              "empty": {
+                "summary": "No programs (例)",
+                "value": { "programs": [] }
+              }
+            }
           }
         }
       },

31-40: エラーレスポンスの JSON 形状を定義してください

現在 400/404/500 は description のみで schema がありません。クライアント側が扱いやすいよう、共通 Error スキーマを定義して参照させましょう。

       "400": {
-        "description": "Bad request"
+        "description": "Bad request",
+        "content": {
+          "application/json": {
+            "schema": { "$ref": "#/components/schemas/Error" }
+          }
+        }
       },
       "404": {
-        "description": "Not found"
+        "description": "Not found",
+        "content": {
+          "application/json": {
+            "schema": { "$ref": "#/components/schemas/Error" }
+          }
+        }
       },
       "500": {
-        "description": "Internal server error"
+        "description": "Internal server error",
+        "content": {
+          "application/json": {
+            "schema": { "$ref": "#/components/schemas/Error" }
+          }
+        }
       }
   "components": {
     "schemas": {
+      "Error": {
+        "type": "object",
+        "properties": {
+          "code": { "type": "string", "example": "BAD_REQUEST" },
+          "message": { "type": "string", "example": "Invalid query" },
+          "details": { "type": "object", "additionalProperties": true }
+        },
+        "required": ["code", "message"],
+        "additionalProperties": false
+      },

Also applies to: 44-201


46-53: スキーマの厳格化(additionalProperties, minItems)と再利用性の向上

  • 主要オブジェクトに additionalProperties: false を付けて未知キーをはじくとデータ品質が上がります。
  • 配列に minItems(可能なら maxItems も)を追加すると Lint(CKV_OPENAPI_21)回避と契約の明確化になります。
  • Program / Boat を個別スキーマとして切り出し、$ref で参照すると保守性が上がります。

最小差分例:

   "BoatraceOpenAPI": {
     "type": "object",
     "properties": {
       "programs": {
         "type": "array",
+        "minItems": 0,
         "items": {
-          "type": "object",
+          "type": "object",
           "properties": {
             ...
-          }
+          },
+          "additionalProperties": false
         }
       }
     },
     "required": ["programs"],
+    "additionalProperties": false
   }

(可能であれば components.schemas.Programcomponents.schemas.Boat を追加し、items: { "$ref": "#/components/schemas/Program" }Program.properties.boats.items"$ref": "#/components/schemas/Boat" に差し替え)

Also applies to: 79-81, 151-179, 182-194, 196-201


3-7: メタ情報の拡充(任意)

info.licenseinfo.contact を追加すると利用者に親切です。API の再配布条件や問い合わせ先を明示できます。

docs/v2/index.html (3)

2-2: を指定してアクセシビリティを改善

言語を明示してください(例: 日本語サイトなら lang="ja")。スクリーンリーダーや検索エンジンに有益です。

-<html>
+<html lang="ja">

3-7: モバイル対応とCDNのバージョン固定/SRI

  • モバイル表示のため meta viewport を追加。
  • ReDoc の CDN を latest ではなく固定バージョン+SRIにすると将来の破壊的変更を回避できます(具体版は運用方針に合わせて選定)。
   <head>
     <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
     <title>Boatrace Open API for Programs</title>
-    <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
+    <!-- 例: バージョン固定(SRIは実際の値に置換してください) -->
+    <script src="https://cdn.redoc.ly/redoc/v2.1.2/bundles/redoc.standalone.js"
+            integrity="sha384-...actual_hash..."
+            crossorigin="anonymous"></script>
   </head>

8-10: フォールバックを追加(任意)

JS 無効時の案内を出すと UX が向上します。

   <body>
     <redoc spec-url="openapi.json"></redoc>
+    <noscript>このページを表示するには JavaScript を有効にしてください。</noscript>
   </body>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3a9492e and 1917f9c.

📒 Files selected for processing (2)
  • docs/v2/index.html (1 hunks)
  • docs/v2/openapi.json (1 hunks)
🧰 Additional context used
🪛 Checkov (3.2.334)
docs/v2/openapi.json

[HIGH] 1-202: Ensure that the global security field has rules defined

(CKV_OPENAPI_4)


[HIGH] 1-202: Ensure that security operations is not empty.

(CKV_OPENAPI_5)


[MEDIUM] 49-194: Ensure that arrays have a maximum number of items

(CKV_OPENAPI_21)

🔇 Additional comments (2)
docs/v2/openapi.json (1)

8-16: 公開URLの実在を最終確認してください(GitHub Pages 配置との整合)

servers[0].urlpaths の組み合わせで解決される実URLは
https://boatraceopenapi.github.io/programs/v2/today.json になります。プロジェクトページ運用(/programs/ プレフィックス)かどうかで変わるため、公開後に 200 が返ることを確認ください(root ページ運用なら paths 側の /programs を外す必要があります)。

Also applies to: 15-41

docs/v2/index.html (1)

8-10: spec-url の相対パスは配置と一致するか確認

openapi.json がこの HTML と同じディレクトリにある前提です。/programs/v2/ 以外に配置する場合はパス調整が必要です。

Comment thread docs/v2/openapi.json
Comment on lines +64 to +66
"race_closed_at": {
"type": "string"
},
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Aug 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

型の一貫性とバリデーション(特にパーセンテージ系)を強化

  • race_closed_at は日時なら format: date-time を付与。
  • パーセンテージ系は小数点の可能性が高いので type: numberminimum: 0/maximum: 100 を推奨。
  • racer_assigned_motor_top_2_percent のみ integer*_top_3_percentnumber と不一致です。統一しましょう。

例(該当箇所のみ抜粋、他の % フィールドも同様に適用):

   "race_closed_at": {
-    "type": "string"
+    "type": "string",
+    "format": "date-time"
   },
   "racer_assigned_motor_top_2_percent": {
-    "type": "integer"
+    "type": "number",
+    "minimum": 0,
+    "maximum": 100
   },
   "racer_assigned_motor_top_3_percent": {
-    "type": "number"
+    "type": "number",
+    "minimum": 0,
+    "maximum": 100
   },
   "racer_assigned_boat_top_2_percent": {
-    "type": "number"
+    "type": "number",
+    "minimum": 0,
+    "maximum": 100
   },
   "racer_assigned_boat_top_3_percent": {
-    "type": "number"
+    "type": "number",
+    "minimum": 0,
+    "maximum": 100
   }

Also applies to: 114-152

🤖 Prompt for AI Agents
In docs/v2/openapi.json around lines 64-66 and 114-152, the schema types and
validation for datetime and percentage fields are inconsistent: add "format:
date-time" to race_closed_at, change all percentage-like fields to type: number
with minimum: 0 and maximum: 100 (including racer_assigned_motor_top_2_percent
which is currently integer) so they are consistent and allow decimals, and keep
any truly integer-only fields explicitly typed integer if intended; update the
schema entries accordingly for all % fields in the indicated range.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

細かい修正は後でやります。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shimomo 了解しました!細かい型の調整は後回しで問題ありませんね。現在の仕様書でも基本的な API ドキュメント機能は十分動作しますし、必要に応じて後で改善していけば良いと思います。

@shimomo shimomo merged commit 20d310c into gh-pages Aug 31, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant