- How do I generate JSON Schema for Laravel DTOs using apie/schema-generator?
- Use `ComponentsBuilderFactory::createComponentsBuilderFactory()` to create a factory, then call `addCreationSchemaFor()` with your DTO class name. This generates a `cebe/php-openapi` schema object for your DTO, which you can integrate into Laravel’s API documentation or validation pipelines.
- Does apie/schema-generator work with Laravel’s native types like Carbon or Collections?
- Not out of the box—it’s designed for Apie’s abstractions (DTOs, value objects). To support Laravel types, extend `ComponentsBuilderFactory` or create custom adapters mapping `Carbon`, `Collection`, or Eloquent models to Apie-compatible structures.
- Can I use this package to auto-generate Laravel FormRequest validation rules?
- Yes, but indirectly. Generate schemas first, then parse them to create `rules()` arrays in FormRequests. For example, map `required: true` in schemas to `required` in Laravel’s validation rules, or use a helper library like `spatie/laravel-validation-extensions` for conversion.
- What Laravel versions and PHP versions are supported by apie/schema-generator?
- The package requires PHP 8.0+ and works seamlessly with Laravel 9, 10, and 11. It has no direct conflicts with Laravel’s core dependencies, but ensure your project’s PHP version aligns with these requirements.
- How do I integrate generated schemas with darkaonline/l5-swagger for full OpenAPI docs?
- Generate schemas with `apie/schema-generator`, then merge them into `l5-swagger`’s OpenAPI structure. Use `cebe/php-openapi` to combine the components/schemas section with paths, security, or servers defined in `l5-swagger` for a complete spec.
- Will this package slow down my Laravel application if I generate schemas on every request?
- Yes, schema generation can be resource-intensive. Cache the generated schemas using Laravel’s cache system (e.g., `Illuminate/Cache`) or trigger generation during deployments or via `php artisan` commands to avoid runtime overhead.
- Can apie/schema-generator handle nested or recursive DTO structures?
- Yes, it supports nested objects and references (`$ref`) automatically. For recursive structures (e.g., self-referencing DTOs), ensure your objects implement Apie’s interfaces like `DtoInterface` and use `$ref` to avoid infinite loops in schema generation.
- What’s the difference between apie/schema-generator and spatie/laravel-fractal for API schemas?
- apie/schema-generator focuses on generating JSON Schema components from PHP type hints, ideal for validation and OpenAPI/Swagger docs. spatie/laravel-fractal transforms Eloquent models into API resources but lacks deep type-hint integration. Use both for a full pipeline: generate schemas with `apie` and format responses with `fractal`.
- How do I test schema generation in a Laravel CI/CD pipeline?
- Write unit tests comparing generated schemas to expected outputs using PHPUnit. For integration tests, validate schemas against Laravel’s `Validator` or `l5-swagger`’s OpenAPI parser. Trigger schema generation in CI via a custom `php artisan` command or Git hooks.
- Is apie/schema-generator suitable for production use in large-scale Laravel APIs?
- Yes, but with caveats. Cache generated schemas aggressively and monitor performance. For critical APIs, combine it with `l5-swagger` or `zircote/swagger-php` to ensure full OpenAPI compliance. Test thoroughly with tools like Postman or Pact for contract validation.