Skip to content

型生成スクリプトの設置#240

Open
kitsne241 wants to merge 2 commits into
mainfrom
chore/generate-type-aliases
Open

型生成スクリプトの設置#240
kitsne241 wants to merge 2 commits into
mainfrom
chore/generate-type-aliases

Conversation

@kitsne241

@kitsne241 kitsne241 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

関連:#239

src/api/schema.d.ts にルートレベルの型エイリアスを自動生成するスクリプト generate-types.ts を追加し、その実行で pnpm generate:api を置き換えてみました

これまで合宿型は Camp、ユーザー型は User のようにシンプルな名前の型エイリアスを手動で追加していましたが、openapi-typescript はレスポンス型について SomeResponse という名前で出力し、これを単に Some として出力するオプションは見当たりません

これを後から Some という型名に書き換えるスクリプトが generate-types.ts です。schema.d.ts の振る舞いの全容を把握できていないので、副作用の可能性については検討し切れていませんが、ひとまず手元のデータではうまくいきます

export type CampRequest = components['schemas']['CampRequest']
export type Camp = components['schemas']['CampResponse']
export type EventRequest = components['schemas']['EventRequest']
export type Event = components['schemas']['EventResponse']
export type DurationEventRequest = components['schemas']['DurationEventRequest']
export type DurationEvent = components['schemas']['DurationEventResponse']
...

Summary by CodeRabbit

  • Chores
    • APIスキーマ自動生成プロセスを改善し、安全な一時処理と自動整形を行うように変更しました(生成フローの安定化)。
    • 多数のAPI関連型定義(リクエスト/レスポンス/パラメータ)が追加され、型参照が充実しました。

Copilot AI review requested due to automatic review settings June 4, 2026 14:40
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Too much diff to scan? Review this PR in Change Stack to start with the highest-impact changes.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 452b3ca0-8b09-49fa-a7ce-1efa28610e31

📥 Commits

Reviewing files that changed from the base of the PR and between 7e1426c and b1c2ec5.

📒 Files selected for processing (1)
  • generate-types.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • generate-types.js

📝 Walkthrough

Walkthrough

OpenAPI スキーマから TypeScript 型定義を生成する処理を改善。カスタム generate-types.js スクリプトで openapi-typescript の出力を加工し、Response 接尾辞を削除してから src/api/schema.d.ts に保存。ビルドスクリプトも更新し、多数の型エイリアスを追加。

Changes

OpenAPI型生成パイプラインの改善

Layer / File(s) Summary
型生成スクリプト実装とビルド統合
generate-types.js, package.json
generate-types.js を追加し、リモートの openapi.yaml から openapi-typescript で一時ファイルを生成後、Response 接尾辞を削除して src/api/schema.d.ts に書き込む処理を実装。出力ディレクトリ作成、一時ファイル削除、エラーハンドリングを含む。package.jsongenerate:api スクリプトをこのスクリプト経由に切替。
生成された型エイリアスの定義
src/api/schema.d.ts
components['schemas']components['responses']components['parameters'] を参照する多数の export type エイリアス(リクエスト/レスポンス/パラメータ等)を追加。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトル「型生成スクリプトの設置」は、追加された generate-types.js ファイルと package.json の変更内容を的確に反映している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/generate-type-aliases

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@generate-types.js`:
- Around line 39-42: The catch block in generate-types.js currently only logs
the error and removes TEMP_FILE, allowing the process to exit with a success
code; modify the catch for the error handling in the generateTypes flow (the
catch that references TEMP_FILE) to either rethrow the caught error or call
process.exit(1) after performing the existing cleanup to ensure a non-zero exit
code is returned (keep the fs.existsSync(TEMP_FILE) fs.unlinkSync(TEMP_FILE)
cleanup). Ensure the log remains but the process does not silently succeed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ada2688-7d95-4890-bf81-6031c8d79859

📥 Commits

Reviewing files that changed from the base of the PR and between 0fa0856 and 7e1426c.

📒 Files selected for processing (3)
  • generate-types.js
  • package.json
  • src/api/schema.d.ts

Comment thread generate-types.js

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces an automated workflow for generating root-level TypeScript type aliases from the rucQ OpenAPI schema, aiming to provide simpler alias names (e.g., Camp instead of CampResponse) and replace the previous pnpm generate:api pipeline.

Changes:

  • Add a generation script (generate-types.js) that runs openapi-typescript and post-processes exported *Response root type aliases into non-suffixed names.
  • Update generate:api in package.json to use the new script and format the generated schema.d.ts.
  • Update the generated src/api/schema.d.ts to include many new root-level type aliases.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/api/schema.d.ts Adds generated root-level type aliases (including *Response → non-suffixed aliases).
package.json Switches generate:api to run the new generator script and format the output file.
generate-types.js Implements the OpenAPI → TypeScript generation plus *Response alias renaming.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread generate-types.js
Comment on lines +39 to +42
} catch (error) {
console.error('型定義の生成中にエラーが発生しました:', error)
if (fs.existsSync(TEMP_FILE)) fs.unlinkSync(TEMP_FILE)
}
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.

2 participants