- How do I install this package in a Laravel project?
- Run `composer require devizzent/cebe-php-openapi` in your project root. The package supports PHP 7.1+ and integrates seamlessly with Laravel’s Symfony-based components. No additional Laravel-specific setup is required beyond Composer installation.
- Does this package support OpenAPI 3.1 features like JSON Schema 2020-12?
- Yes, this fork explicitly adds OpenAPI 3.1 support, including JSON Schema 2020-12. The package validates against both 3.0.x and 3.1.x schemas, making it future-proof for newer API specifications. Test coverage includes regression checks for both versions.
- Can I use the CLI tool to validate OpenAPI specs in Laravel’s CI pipeline?
- Absolutely. The `php-openapi validate` command exits with non-zero status on errors (2 for schema violations, 1 for parsing issues), making it ideal for CI/CD pipelines. Integrate it via `vendor/bin/php-openapi validate api-spec.yaml` in your build script.
- Will this work with Laravel 10/11 and Symfony YAML 8.x?
- Yes, the package is explicitly compatible with Symfony YAML 8.x, aligning with Laravel 10/11’s Symfony 6.4+ stack. However, verify your `composer.json` constraints—some projects may still need `symfony/yaml:^6.0` to avoid conflicts with Laravel’s dependencies.
- How do I load an OpenAPI spec from a Laravel config file (e.g., `config/openapi.yaml`)?
- Use Symfony’s YAML parser (included via this package) to load the file: `$yaml = file_get_contents(config_path('openapi.yaml')); $openapi = OpenApi::parse($yaml)`. For cached specs, store the parsed object in Laravel’s cache: `Cache::remember('openapi-spec', 3600, fn() => OpenApi::parse(...));`.
- Are there performance concerns when parsing large OpenAPI specs (e.g., 500+ endpoints)?
- Parsing performance remains unchanged from the original library, but Symfony YAML 8.x may introduce minor overhead. Mitigate this by caching parsed objects (e.g., `Cache::forever()`) or benchmarking with your specific spec size. The CLI tool avoids PHP overhead for repeated validations.
- Can I extend OpenAPI schemas with custom Laravel-specific annotations?
- Yes, leverage Symfony’s YAML tags to add custom annotations. For example, define a `laravel:auth` tag in your YAML and extend the parser to handle it. The package’s object model allows deep customization of schema components without modifying core functionality.
- What alternatives exist for OpenAPI validation in Laravel?
- Alternatives include Symfony’s `openapi` component (tightly integrated with this package) and `zircote/swagger-php` (legacy support). This fork stands out for its active OpenAPI 3.1 support and Symfony YAML 8 compatibility, which aligns better with modern Laravel stacks.
- How do I test this package in a Laravel unit test?
- Mock the `OpenApi` class or use real specs from `tests/OpenApi` (included in the package). Example: `$spec = OpenApi::parse(file_get_contents(__DIR__.'/spec.yaml')); $this->assertInstanceOf(OpenApi::class, $spec);`. For schema validation, assert CLI exit codes via `Artisan::call('php-openapi validate', ['input' => 'spec.yaml'])`.
- Does this package work with Lumen or other lightweight Laravel frameworks?
- Yes, the package is framework-agnostic and works in Lumen, Laravel, or standalone PHP. Lumen projects benefit from Symfony YAML 8 compatibility (e.g., for config-based API specs) without requiring full Laravel dependencies. Use the same installation and CLI commands as in Laravel.