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 any OpenAPI spec. Each endpoint becomes a CLI command with typed options for path/query params and request bodies. Configure base URL, auth, caching, output formats, redirects, and custom error handling—great with Laravel Zero.

View on GitHub
Deep Wiki
Context7

Create a Laravel command for your OpenAPI specs

Frequently asked questions about Laravel Openapi Cli
How do I install spatie/laravel-openapi-cli in my Laravel project?
Run `composer require spatie/laravel-openapi-cli` in your project directory. The package requires Laravel 10.x+ and PHP 8.1+. No additional configuration is needed for basic usage, but you’ll need to define your OpenAPI spec path in `config/openapi.php` or register it programmatically.
Can I use this package with Laravel Zero for standalone CLI tools?
Yes, the package is explicitly designed to work with Laravel Zero. It generates Artisan commands from OpenAPI specs, making it ideal for building lightweight, API-focused CLI tools without a full Laravel frontend.
What OpenAPI versions does this package support (Swagger 2.0, OpenAPI 3.x)?
The package supports OpenAPI 3.x (including 3.0, 3.1) and Swagger 2.0 specs. It relies on `zircote/swagger-php` for parsing, so ensure your spec adheres to one of these versions. Complex specs with `$ref` or nested schemas should work, but validate them pre-integration.
How do I configure authentication (Bearer tokens, API keys) for generated commands?
Use the fluent `register()` method to set auth. For Bearer tokens, chain `->bearer('your_token')` or `->bearer(env('TOKEN_KEY'))`. For API keys, use `->header('X-API-Key', 'value')`. You can also inject auth dynamically via the `onBeforeRequest` callback.
Will generated commands cache API responses, or do they hit live endpoints every time?
By default, commands hit live endpoints. Enable caching with `->cache(ttl: 300)` to store responses for a specified time (in seconds). Cached responses are stored in Laravel’s default cache driver (e.g., file, Redis).
Can I filter which OpenAPI endpoints become CLI commands? For example, only generate commands for `/users` endpoints.
Yes, use the `--filter` flag during generation, e.g., `php artisan openapi:generate --filter '/users'`. You can also filter by HTTP method (e.g., `--filter-method GET`) or operation ID if your spec uses them.
How do I handle custom error responses or rate limiting in generated commands?
Use the `onError` callback in the `register()` method to define custom logic. For example, detect 429 responses and show a retry message: `->onError(fn($response) => $response->status() === 429 ? 'Rate limited' : false)`. You can also throw exceptions or log errors.
Does this package work with Laravel packages (e.g., for reusable API contracts)?
Yes, the package is built with Laravel packages in mind. You can publish the OpenAPI config or register specs programmatically in a service provider, making it reusable across microservices or monoliths sharing the same API contracts.
What’s the best way to test generated commands before deploying to production?
Use the `openapi:generate` command with `--dry-run` to preview commands without executing them. For integration tests, mock HTTP responses with Laravel’s `Http::fake()` or use `symfony/process` to test CLI output. Validate edge cases like auth failures or malformed requests.
Are there alternatives to this package for generating CLI tools from OpenAPI specs?
Alternatives include `openapi-generator` (multi-language CLI tool) or custom scripts using `zircote/swagger-php` to parse specs and generate PHP code. However, this package is Laravel-native, offering seamless integration with Artisan, caching, and Laravel Zero, which alternatives lack.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport