Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Laravelで手軽にAPIドキュメントを生成する ― Scribe活用術

SAW
May 26, 2026

Laravelで手軽にAPIドキュメントを生成する ― Scribe活用術

Laravel Live Japan 2026 の発表資料です。

SAW

May 26, 2026

Transcript

25 slides
  1. Scribe とは? API ドキュメントを生成するための Laravel のライブラリ 理解しやすく実際に動かせる Web UI OpenAPI

    仕様書や Postman collection の生成が可能 Laravel 特化の機能 7 Laravel Live Japan 2026
  2. インストール方法 1. Composer 経由でインストール 2. 設定ファイルを生成 前提条件 PHP 8.1 以上

    Laravel 9 以上 composer require knuckleswtf/scribe php artisan vendor:publish --tag=scribe-config 8 Laravel Live Japan 2026
  3. 最もシンプルな使い方 1. routes/api.php に API の route を定義 2. php

    artisan scribe:generate を実行してドキュメントを生成 /docs から生成されたドキュメントが確認可能 Route::get('/sample', [SampleController::class, 'sample']); Laravel Live Japan 2026 9
  4. レスポンスの出力例を追加 1. 出力例を生成する対象を config/scribe.php で設定 only 引数で対象とするエンドポイントを指定 only 引数を省略するとすべてのエンドポイントが対象 2.

    php artisan scribe:generate を実行 'responses' => configureStrategy( Defaults::RESPONSES_STRATEGIES, Strategies\Responses\ResponseCalls::withSettings( only: ['GET *'], config: ['app.debug' => false], ), ), Laravel Live Japan 2026 12
  5. レスポンスの出力例を追加 1. 出力例を生成する対象を config/scribe.php で設定 only 引数で対象とするエンドポイントを指定 only 引数を省略するとすべてのエンドポイントが対象 2.

    php artisan scribe:generate を実行 only: ['GET *'], 'responses' => configureStrategy( Defaults::RESPONSES_STRATEGIES, Strategies\Responses\ResponseCalls::withSettings( config: ['app.debug' => false], ), ), Laravel Live Japan 2026 12
  6. レスポンスの出力例を追加 1. 出力例を生成する対象を config/scribe.php で設定 only 引数で対象とするエンドポイントを指定 only 引数を省略するとすべてのエンドポイントが対象 2.

    php artisan scribe:generate を実行 only: ['GET *', 'POST *'], 'responses' => configureStrategy( Defaults::RESPONSES_STRATEGIES, Strategies\Responses\ResponseCalls::withSettings( config: ['app.debug' => false], ), ), Laravel Live Japan 2026 12
  7. レスポンスの出力例を追加 1. 出力例を生成する対象を config/scribe.php で設定 only 引数で対象とするエンドポイントを指定 only 引数を省略するとすべてのエンドポイントが対象 2.

    php artisan scribe:generate を実行 'responses' => configureStrategy( Defaults::RESPONSES_STRATEGIES, Strategies\Responses\ResponseCalls::withSettings( config: ['app.debug' => false], ), ), Laravel Live Japan 2026 12
  8. その他の機能 #[Endpoint()] : エンドポイントのタイトルや説明を追加 #[UrlParam()] : URL パラメーターの詳細を追加 #[QueryParam()] ,

    #[BodyParam()] : クエリパラメタやリクエストボディの詳細を追加 #[ResponseFromApiResource()] : ApiResource からレスポンス例を生成 etc… public function find(int $id): SampleMessageResource { $message = SampleMessage::findOrFail($id); return new SampleMessageResource($message); } Laravel Live Japan 2026 14
  9. その他の機能 #[Endpoint()] : エンドポイントのタイトルや説明を追加 #[UrlParam()] : URL パラメーターの詳細を追加 #[QueryParam()] ,

    #[BodyParam()] : クエリパラメタやリクエストボディの詳細を追加 #[ResponseFromApiResource()] : ApiResource からレスポンス例を生成 etc… #[Endpoint('Find The Sample Message', 'Return the sample message.')] public function find(int $id): SampleMessageResource { $message = SampleMessage::findOrFail($id); return new SampleMessageResource($message); } Laravel Live Japan 2026 14
  10. その他の機能 #[Endpoint()] : エンドポイントのタイトルや説明を追加 #[UrlParam()] : URL パラメーターの詳細を追加 #[QueryParam()] ,

    #[BodyParam()] : クエリパラメタやリクエストボディの詳細を追加 #[ResponseFromApiResource()] : ApiResource からレスポンス例を生成 etc… #[UrlParam('id', 'integer', 'The ID of the message.')] public function find(int $id): SampleMessageResource #[Endpoint('Find The Sample Message', 'Return the sample message.')] { $message = SampleMessage::findOrFail($id); return new SampleMessageResource($message); } Laravel Live Japan 2026 14
  11. その他の機能 #[Endpoint()] : エンドポイントのタイトルや説明を追加 #[UrlParam()] : URL パラメーターの詳細を追加 #[QueryParam()] ,

    #[BodyParam()] : クエリパラメタやリクエストボディの詳細を追加 #[ResponseFromApiResource()] : ApiResource からレスポンス例を生成 etc… #[ResponseFromApiResource(SampleMessageResource::class, SampleMessage::class)] return new SampleMessageResource($message); #[Endpoint('Find The Sample Message', 'Return the sample message.')] #[UrlParam('id', 'integer', 'The ID of the message.')] public function find(int $id): SampleMessageResource { $message = SampleMessage::findOrFail($id); } Laravel Live Japan 2026 14
  12. その他の機能 #[Endpoint()] : エンドポイントのタイトルや説明を追加 #[UrlParam()] : URL パラメーターの詳細を追加 #[QueryParam()] ,

    #[BodyParam()] : クエリパラメタやリクエストボディの詳細を追加 #[ResponseFromApiResource()] : ApiResource からレスポンス例を生成 etc… #[Endpoint('Find The Sample Message', 'Return the sample message.')] #[UrlParam('id', 'integer', 'The ID of the message.')] #[ResponseFromApiResource(SampleMessageResource::class, SampleMessage::class)] public function find(int $id): SampleMessageResource { $message = SampleMessage::findOrFail($id); return new SampleMessageResource($message); } Laravel Live Japan 2026 14

More Decks by SAW

Other Decks in Programming