Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Openapi Cli

Laravel Openapi Cli Laravel Package

spatie/laravel-openapi-cli

Generate Laravel Artisan commands from an OpenAPI spec. Each API endpoint becomes its own command with typed options for params and request bodies, plus auth, base URL, caching, redirects, and output formatting—ideal for building API CLIs with Laravel Zero.

View on GitHub
Deep Wiki
Context7

Create a Laravel command for your OpenAPI spec(s). Works in apps and other packages. Useful for AI agents.

Frequently asked questions about Laravel Openapi Cli
How do I generate Laravel Artisan commands from an OpenAPI spec?
Use the `OpenApiCli::register()` method in your `AppServiceProvider` or a dedicated service provider. Pass the OpenAPI spec URL (local file or remote) and a namespace (e.g., 'bookstore'). The package automatically generates commands for each endpoint with typed options for path/query/body inputs.
Does this package work with Laravel Zero for standalone CLI tools?
Yes, it’s fully compatible with Laravel Zero. Register the API in your `AppServiceProvider` or `bootstrap/app.php`, then use the generated commands in your CLI tool. The package avoids Laravel’s web dependencies, making it lightweight for standalone tools.
What Laravel versions does spatie/laravel-openapi-cli support?
The package supports Laravel 10+ and requires PHP 8.1+. It’s tested against the latest stable Laravel releases and leverages Laravel’s HTTP client, Artisan, and service provider bootstrapping for seamless integration.
Can I use multiple OpenAPI specs in the same Laravel app?
Absolutely. Register each API with a unique namespace (e.g., `bookstore:`, `payments:`). Commands are namespaced to avoid conflicts, and you can configure each API independently with its own base URL, auth, and caching settings.
How do I handle authentication for API endpoints?
Use methods like `bearer()`, `basic()`, or `custom()` during registration. For dynamic auth (e.g., OAuth tokens), pass a closure to `custom()` that resolves the token at runtime. Static auth (e.g., `bearer(env('API_TOKEN'))`) is simpler but less flexible.
What happens if my OpenAPI spec changes or is invalid?
The package doesn’t enforce spec validation, so poorly structured specs may generate unusable commands. Test your spec locally first (e.g., with Swagger UI) and ensure it includes clear `operationId`s and path parameters. Cache remote specs to avoid repeated fetches during development.
Can I customize error handling for API responses?
Yes, use the `onError()` method during registration to define custom behavior. For example, handle rate limits (429) with warnings or retry logic. Default error handling logs failures but doesn’t retry, so extend it for production resilience (e.g., exponential backoff).
How do I test commands generated from OpenAPI specs?
Mock Laravel’s HTTP client (e.g., with `Http::fake()`) to simulate API responses. Test individual commands using PHPUnit’s `Artisan::call()` method. For integration tests, use real APIs in a staging environment or with API mocking tools like VCR.
Are there performance concerns with remote OpenAPI specs?
Remote specs are fetched once on boot and cached (configurable TTL). Command generation is dynamic, so there’s no runtime penalty beyond HTTP calls to the API. For large specs, cache locally or use a CDN to reduce fetch latency.
What alternatives exist for CLI-driven API interactions in Laravel?
For lightweight CLI tools, consider manually writing Artisan commands with Guzzle or Symfony’s HTTP client. For OpenAPI-first approaches, tools like OpenAPI Generator (Node.js) or Spectral CLI can generate SDKs, but they lack Laravel’s Artisan integration. This package bridges the gap by natively embedding OpenAPI specs into Laravel’s CLI ecosystem.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai