- How do I install erasys/openapi-php in a Laravel project?
- Install it with Composer as a development dependency using composer require erasys/openapi-php --dev. It has no Laravel service provider or config surface advertised, so expect to create your own wrapper service class and Artisan command. Keep it in require-dev unless you genuinely need to emit or validate specs at runtime.
- Does erasys/openapi-php have a Laravel service provider or config file?
- No native Laravel bindings are advertised. Integration is bring-your-own wiring, typically an App\OpenApi module with schema definitions, a service class, and an openapi:generate command. Treat it as a framework-agnostic PHP tool rather than a Laravel package with automatic discovery.
- Is erasys/openapi-php compatible with Laravel 10 and Laravel 11?
- It is a framework-agnostic pure PHP library, so Laravel compatibility depends on its PHP and Composer constraints matching your application matrix. Confirm the package constraints against Laravel 10 or 11 running on PHP 8.2 or 8.3 before adopting it. Pin the version and test it during framework upgrades because an unmaintained dependency can block future upgrades.
- Can I generate OpenAPI docs from Laravel routes, form requests, and Eloquent resources?
- Yes, but you build the spec programmatically rather than relying on annotation scanning. You model schemas, paths, operations, parameters, and responses with the package's fluent builders, then map your routes, form requests, Eloquent resources, and DTOs into those objects yourself. The main effort is defining conventions and a dedicated spec-builder namespace inside your Laravel app.
- Does erasys/openapi-php support OpenAPI 3.1?
- The package targets OpenAPI 3.0, and the technical evaluation flags OpenAPI 3.1 support as an unconfirmed gap. If your consuming tooling needs 3.1 features such as JSON Schema 2020-12 semantics or webhooks, verify the roadmap before adopting it. Otherwise plan around OpenAPI 3.0.x and validate the generated artifact with your downstream tools.
- How do I validate an OpenAPI spec with erasys/openapi-php?
- The library helps you build and validate the resulting OpenAPI specification, so you can run validation from a test or an Artisan command. It is not a runtime request validator for incoming API traffic. Pair spec validation with Laravel form requests or dedicated runtime validation for actual HTTP requests.
- Is erasys/openapi-php a runtime request validator for Laravel APIs?
- No, it is a documentation and contract builder, not a runtime request validator. Use Laravel validation, form requests, or dedicated middleware to validate incoming requests at runtime. Use this package to generate and validate the OpenAPI spec artifact consumed by Swagger UI, Redoc, client generators, or API gateways.
- Can I test OpenAPI spec generation with PHPUnit or Pest in Laravel?
- Yes, because it is pure PHP and can be exercised from PHPUnit or Pest like any other code path. Generate the spec in a test and assert its structure or validate it as part of CI. This makes spec generation reviewable and helps prevent documentation drift.
- Is erasys/openapi-php actively maintained and safe for production?
- Adoption is narrow, with roughly 20 GitHub stars and a last release in November 2023, so maintenance risk is the dominant concern. Treat it as a dev or tooling dependency rather than a production runtime dependency, and pin the version. Check commit cadence and maintainer bus factor, and keep a fork-and-own fallback as a contingency.
- What are alternatives to erasys/openapi-php in Laravel, and can I swap it later?
- The de facto PHP alternative is zircote/swagger-php, while some teams prefer a design-first YAML workflow. This package trades ecosystem familiarity for a cleaner programmatic API using typed classes and fluent builders. Wrap it behind a stable internal interface so you can replace it with swagger-php or design-first YAML without rewriting consumers.