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.
illuminate/http), ensuring tight integration with the framework’s ecosystem. The facade-based API (OpenApiCli) aligns with Laravel’s common patterns (e.g., Hash, Cache).->auth()->cache()->retryOn() mirrors Laravel’s fluent interfaces (e.g., query builders, mailables), improving readability and maintainability.spatie/laravel-openapi-cli).OpenApiCli::register() in a config file or bootstrapped service).app() helper, HTTP client). Risk: ~3–5 hours of dev time for a custom wrapper.** paths).illuminate/http and spatie/array-to-object). Conflicts unlikely unless using highly customized Laravel versions.| Risk Area | Severity | Mitigation |
|---|---|---|
| OpenAPI Spec Quality | High | Validate specs with tools like Swagger Editor pre-integration. |
| Auth Complexity | Medium | Test with OAuth2/API keys early. Use retryOn() for token refresh logic. |
| Parameter Parsing | Low | Fixed in v1.0.1; edge cases (e.g., query params with special chars) are handled. |
| Performance | Low | Caching (->cache(ttl: ...)) mitigates spec parsing overhead. |
| Laravel Zero Limitations | Medium | Ensure Laravel Zero’s handle() method is compatible with generated commands. |
| Output Formatting | Low | Customize with ->yamlOutput() or ->jsonOutput(); extend via facades. |
retryOn() suffice for token refresh, or is a custom solution needed?->onError()) or integrate with Laravel’s exception handling?list command replace or supplement existing API docs?--help output)?illuminate/http for requests (supports middleware, retries).OAuthTokenManager).php artisan myapp:command).app() helper (e.g., via Symfony/DependencyInjection).illuminate/http with Guzzle/HTTP client.OpenApiCli::register('https://api.example.com/openapi.yaml', 'example-api')
->baseUrl('https://api.example.com')
->auth(fn () => $this->authManager->token());
php artisan example-api:get-users).auth-api, payment-api).api:command instead of curl").| Component | Compatibility | Notes |
|---|---|---|
| Laravel Versions | 8.x–10.x (tested) | Uses Laravel’s HTTP client and Artisan. |
| OpenAPI Versions | 3.0.x–3.1.x | YAML/JSON support; no OpenAPI 2.0. |
| Auth Schemes | OAuth2, API keys, Bearer tokens, Basic Auth | Custom auth via closures (e.g., ->auth(fn () => ...)). |
| HTTP Clients | Guzzle (under the hood) | Middleware/retries supported via Laravel’s HTTP client. |
| Laravel Zero | Full support | Commands work as Zero app routes. |
| Non-Laravel PHP | Possible with wrappers | Requires DI container and HTTP client mocking. |
composer require spatie/laravel-openapi-cli.AppServiceProvider).php artisan api:list).->auth()).->onError()).->yamlOutput()).php artisan api:command --help.php artisan api:command calls).api:get-users) may not match team conventions. **How can I help you explore Laravel packages today?