knuckleswtf / scribe

Generate API documentation for humans from your Laravel codebase.✍
https://scribe.knuckles.wtf/laravel/
MIT License
1.58k stars 280 forks source link

Endpoint level URL params for OpenAPI spec #803

Closed coxta closed 4 months ago

coxta commented 4 months ago

Move URL parameters down to the endpoint level for the OpenAPI specification. This can help improve some http clients ability to import and render the spec correctly.

Example Routes

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\v1\TruckController;

/**
 * Search Trucks
 * 
 */
Route::get('trucks', [TruckController::class, 'search'])->name('demo.search');

/**
 * View Truck
 * 
 * @urlParam id string Unique identifier for the truck
 */
Route::get('trucks/{id}', [TruckController::class, 'view'])->name('demo.view');

BEFORE

openapi.yaml

paths:
  /trucks: ...
  '/trucks/{id}':
    get:
      summary: 'View a Truck'
      operationId: getTrucksId
      description: 'View a specific Truck'
      parameters: []
      responses: ...
      tags: ...
      security: []
    parameters:
      -
        in: path
        name: id
        description: 'The ID of the truck.'
        example: provident
        required: true
        schema:
          type: string

HTTP Client

image

AFTER

openapi.yaml

paths:
  /trucks: ...
  '/trucks/{id}':
    get:
      summary: 'View a Truck'
      operationId: getTrucksId
      description: 'View a specific Truck'
      parameters:
        -
          in: path
          name: id
          description: 'The ID of the truck.'
          example: trk123
          required: true
          schema:
            type: string
      responses: ...
      tags: ...
      security: []

HTTP Client

image