Spatie has released Laravel OpenAPI CLI, a package that converts OpenAPI specifications into dedicated Laravel Artisan commands. Each API endpoint in your spec gets its own command, with typed options for path and query parameters, and request bodies.
How It Works
After installing, you register an OpenAPI spec URL using the OpenApiCli facade — typically in your AppServiceProvider:
namespace App\Providers; use Illuminate\Support\ServiceProvider;use Spatie\OpenApiCli\Facades\OpenApiCli; class AppServiceProvider extends ServiceProvider{ public function boot() { OpenApiCli::register('https://api.acme.com/openapi.yaml', 'acme') ->baseUrl('https://api.acme.com') ->bearer(env('ACME_API_TOKEN')); }}
Given a spec that defines GET /orders, POST /orders, and DELETE /orders/{order_id}, the package generates the following Artisan commands:
acme:get-ordersacme:post-ordersacme:delete-ordersacme:list
The acme:list command displays all available endpoints and their descriptions.
Commands follow the pattern {prefix}:{http-method}-{path}, where the prefix is the name given during registration (the 2nd parameter of the register method), and the path is converted to kebab-case with path parameters stripped out. So GET /orders/{order_id}/items becomes acme:get-orders-items. If your spec defines operation IDs, you can use those instead via ->useOperationIds().
Running Commands
You can call any generated command directly from the terminal:
php artisan acme:get-orders --limit=10
Responses render as human-readable tables by default. Pass the --yaml flag for YAML output instead:
php artisan acme:get-orders --limit=10 --yaml
Path and Query Parameters
Path parameters are required options, and query parameters are optional. Both are converted to kebab-case — so order_id and orderId both become --order-id:
# Path parameterphp artisan acme:get-orders-items --order-id=42 # Multiple path parametersphp artisan acme:delete-customers-orders --customer-id=1 --order-id=7 # Query parametersphp artisan acme:get-orders --status=pending --limit=10
Bracket notation in query strings is also flattened to kebab-case, so filter[status] becomes --filter-status.
Sending Data
For endpoints that accept a request body, you can send fields individually using --field:
php artisan acme:post-orders --field customer_id=1 --field status="pending"
Fields are sent as JSON by default, unless the spec specifies application/x-www-form-urlencoded. If you need to send raw JSON, use --input instead:
php artisan acme:post-orders --input '{"customer_id":1,"shipping":{"address":"123 Main St","city":"New York"}}'
Note that --field and --input cannot be combined. For file uploads, prefix the field value with @:
php artisan acme:post-orders-attachments --order-id=67 --field file=@/path/to/invoice.pdf
When any field contains a file, the request is sent as multipart/form-data.
Configuration Options
The registration API also supports several options through a fluent interface:
OpenApiCli::register('https://api.acme.com/openapi.yaml', 'acme') ->baseUrl('https://api.acme.com') ->bearer(env('ACME_API_TOKEN')) ->banner('Acme Orders API v2') ->cache(ttl: 600) ->followRedirects() ->yamlOutput() ->showHtmlBody() ->useOperationIds() ->onError(function (Response $response, Command $command) { return match ($response->status()) { 429 => $command->warn('Rate limited...'), default => false, }; });
A few notable options:
cache(ttl: 600)— Caches responses for the specified number of secondsfollowRedirects()— Automatically follows HTTP redirectsuseOperationIds()— Names commands using the operation IDs from your spec rather than the HTTP method and pathonError()— Accepts a callback for handling specific HTTP error status codes
Installation
Install via Composer:
composer require spatie/laravel-openapi-cli
This package also integrates well with Laravel Zero, a framework for building standalone CLI applications.
Full documentation is available on Spatie's docs site, and you can view the source code on GitHub.