Open APIによる仕様書をブラッシュアップ#160
Conversation
他のレスポンスの内容と揃えるため
ヘッダで表現できるから
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary of ChangesHello @ToYama170402, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! このプルリクエストは、 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
このプルリクエストでは、シラバスAPIの仕様がOpenAPI形式で新たに追加されました。APIのエンドポイントとデータモデルが明確に定義されており、プロジェクトにとって素晴らしい追加です。レビューを通して、セキュリティ、保守性、一貫性の観点からいくつかの改善点を提案させていただきました。具体的には、HTTPSの使用、共通スキーマの利用による重複の削減、エラーレスポンスの拡充、そして必須フィールドの見直しなどです。詳細については、各コメントをご確認ください。
I am having trouble creating individual review comments. Click here to see my feedback.
syllabus-backend/doc/api.yml (9)
サーバーのURLがhttpで定義されています。本番環境など、セキュアな通信が求められる場面では、通信を暗号化するためにhttpsを使用することが強く推奨されます。
また、APIに認証・認可の仕組みがある場合は、securitySchemesとsecurityを用いて仕様に明記するべきです。
例えば、以下のように複数のサーバーを定義したり、APIキー認証を追加したりできます。
servers:
- url: https://api.example.com
description: Production server
- url: http://localhost:8080
description: Local development server
security:
- ApiKeyAuth: []
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: X-API-KEY - url: https://{apiHost}:8080syllabus-backend/doc/api.yml (46-72)
facultyパラメータのenumがここで定義されていますが、components/schemas/Facultyスキーマ内(L486-L506)でも同様のenumが定義されています。
このように定義が重複していると、将来enumの値を更新する際に、複数箇所を修正する必要があり、メンテナンス性が低下します。
componentsにFacultyNameのような共通スキーマを定義し、$refで参照することで、重複をなくし、一元管理することをお勧めします。departmentパラメータについても同様です。
例:
components:
schemas:
FacultyName:
type: string
enum:
- 先導学類
- ...
# ...
paths:
/courses:
get:
parameters:
- name: faculty
in: query
schema:
$ref: '#/components/schemas/FacultyName'syllabus-backend/doc/api.yml (184-207)
courseIdのフォーマットが不正な場合(例:整数でない)など、クライアントからのリクエストが不正な場合に返される400 Bad Requestレスポンスが定義されていません。
POST /coursesで定義されているような、エラー詳細を含む400レスポンスを各エンドポイントで定義することが推奨されます。
一貫性を保つために、共通のエラーレスポンススキーマをcomponentsに定義し、それを$refで参照する方法が効果的です。
# components/schemas に共通エラーレスポンスを定義
ErrorResponse:
type: object
properties:
error:
type: string
# 各エンドポイントの responses で参照
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'syllabus-backend/doc/api.yml (291)
API仕様内のdescriptionフィールドで、英語と日本語が混在しています(例:summaryは英語、ここのdescriptionは日本語)。
仕様の一貫性を保つため、主要な言語を一つ(APIのキーワードが英語であるため、英語が望ましい)に統一することをお勧めします。日本語は補足情報として括弧内に記述するなどのルールを設けると良いでしょう。
description: "Course Numbering (科目ナンバリング)"syllabus-backend/doc/api.yml (354-367)
Courseスキーマにおいて、lectureRoomInfo(L366)やenglishUrl(L362)など、多くのフィールドがrequiredとされています。
しかし、実際のデータでは講義室が「未定」であったり、英語のシラバスURLが存在しない場合も考えられます。これらのフィールドを必須にすると、該当する科目の登録や更新ができなくなる可能性があります。
本当に常に必須であるフィールドのみをrequiredとし、それ以外は任意(optional)にすることを検討してください。
syllabus-backend/doc/api.yml (369-443)
CourseResponseスキーマは、courseIdが追加されている点を除き、Courseスキーマとほぼ同じ内容です。これにより多くの重複が生じており、メンテナンス性が低下しています。
OpenAPIのallOfを使用してCourseスキーマを継承・拡張することで、この重複をなくすことができます。
また、現在のCourseResponseにはrequiredプロパティがありません。APIが常に完全なコース情報を返すのであれば、Courseから継承したプロパティとcourseIdをrequiredに指定すべきです。
CourseResponse:
allOf:
- $ref: '#/components/schemas/Course'
- type: object
required:
- courseId
properties:
courseId:
description: Unique identifier for the course (独自ID)
type: integer
readOnly: trueメンテナンス性を向上させるため
変更内容
変更の種類
関連Issue
Closes #
変更の詳細
テスト
テスト内容
チェックリスト
スクリーンショット
その他