- 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 auto-discovers your OpenAPI spec via `config/openapi.php` or uses the default path. No additional configuration is needed for basic usage.
- Which Laravel versions and PHP versions does this package support?
- The package supports Laravel 10.x and 11.x with PHP 8.1 or higher. It is not compatible with Laravel 8.x or PHP 8.0 due to dependency requirements. Check the [GitHub repo](https://github.com/spatie/laravel-openapi-cli) for updates.
- Can I use this package to generate commands for a third-party API (e.g., Stripe, GitHub)?
- Yes, you can register external APIs by specifying their OpenAPI spec URL in your `config/openapi.php` or dynamically via code. The package supports authentication (e.g., Bearer tokens) and custom error handling for third-party APIs.
- How do I handle authentication (OAuth, API keys) in generated commands?
- Authentication is configured during registration. Use methods like `bearer()`, `apiKey()`, or `basicAuth()` when registering the OpenAPI spec. For OAuth, pass tokens via environment variables or command options.
- Will generated commands cache API responses, or will they hit live endpoints every time?
- By default, commands hit live endpoints. You can enable caching with `cache(ttl: $seconds)` during registration. Cached responses are stored in Laravel’s cache driver (e.g., file, Redis).
- Can I extend or customize the generated commands (e.g., add pre/post hooks)?
- Yes, you can extend command behavior using event listeners for `OpenApiCommand` events or by overriding the default command logic in a service provider. The package provides hooks for request/response modification.
- Does this package work in Laravel packages (not just apps)?
- Yes, the package is designed for both Laravel apps and packages. Use `spatie/laravel-package-tools` to publish the OpenAPI config and commands. It’s ideal for sharing API contracts across microservices.
- How do I validate my OpenAPI spec before generating commands?
- Use tools like `swagger-cli validate` or `spectral` to validate your spec before integration. The package relies on `zircote/swagger-php` for parsing, so malformed specs may cause errors during command generation.
- Can I use these commands in CI/CD for API testing?
- Yes, generated commands are ideal for API testing in CI/CD. Use them to validate endpoints, test authentication flows, or simulate user interactions. Combine with Laravel’s testing tools for assertions.
- What are some alternatives to this package for OpenAPI-to-CLI conversion?
- Alternatives include `openapi-generator` (multi-language CLI tools) or custom scripts using `symfony/process` to call APIs via `curl`. However, this package is Laravel-native, offering typed Artisan commands with minimal setup.