- What does michaelalexeevweb/openapi-php-dto-generator do?
- It parses an OpenAPI 3 specification and generates PHP DTO classes for API request and response models. The generated classes include typed properties, constructor signatures, and support for nested objects, so you avoid hand-writing repetitive boilerplate. It works in Laravel applications and in framework-agnostic PHP projects.
- How do I install openapi-php-dto-generator in a Laravel project?
- Install it with Composer using the package name michaelalexeevweb/openapi-php-dto-generator, then follow the repository README for the generation workflow and any required configuration. The package is intended to work in Laravel projects as well as framework-agnostic PHP. Check the repository for the current install command and version constraints.
- Does this package require Laravel, or can I use it in plain PHP?
- It is framework-agnostic and can be used in plain PHP projects as well as Laravel applications. The generated output is ordinary PHP DTO classes, so it does not depend on Laravel runtime components. That makes it suitable for both Laravel codebases and standalone PHP services.
- Which Laravel and PHP versions are supported?
- The package is described as working with Laravel and framework-agnostic PHP, but the exact supported Laravel and PHP versions depend on the release. Check the package's composer.json or repository README for the authoritative version constraints before installing or upgrading. This is especially important when your application is on an older or newer Laravel major version.
- How does the generator handle nested objects and arrays in OpenAPI schemas?
- The package advertises nested object support, so schemas with child objects are represented as structured DTO classes rather than untyped arrays. Typed properties and constructor signatures help preserve the shape of nested API data. Review generated output for complex array and composition cases and adjust your spec or generation workflow as needed.
- How do I configure the generator and regenerate DTOs when my OpenAPI spec changes?
- The package is built for a simple, repeatable generation workflow: point it at your OpenAPI spec and regenerate the DTO classes when the contract changes. Configuration details such as output path and namespace depend on the package version, so confirm them in the repository README. Review generated diffs before committing so schema changes are intentional.
- How can I test generated DTO classes?
- Generated DTOs are plain PHP classes, so you can instantiate them in PHPUnit or Pest tests and assert property values and types. In Laravel, use your normal test suite; no special runtime is needed beyond autoloading the generated classes. Focus tests on constructor behavior, nested object mapping, and edge cases in your OpenAPI schema.
- Is it safe to use generated DTOs in production?
- Yes, generated DTOs are ordinary PHP classes, so they can be autoloaded and used like any other class in production. The main production concern is keeping generated code in sync with the OpenAPI spec and reviewing diffs when the contract changes. Treat generation as a repeatable build step and include the output in your normal code review and test process.
- When should I use this package instead of hand-written DTOs or other OpenAPI generators?
- Use it when you want a narrow, repeatable way to turn OpenAPI 3 schemas into typed PHP DTO classes for Laravel or plain PHP. It is a better fit than hand-writing DTOs when your API contract changes regularly and you want to reduce boilerplate. Broader OpenAPI generators may scaffold more of the API, while this package focuses specifically on DTO generation.
- Is the package actively maintained?
- For maintenance status, check the GitHub repository for recent commits, tagged releases, and open issues. The Composer package name and repository are the authoritative sources for current activity and support. Because generated DTOs are plain PHP, even a stable snapshot remains usable while you evaluate updates.