Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Schema Generator Laravel Package

api-platform/schema-generator

CLI tool from API Platform that generates PHP class models from vocabularies like Schema.org and ActivityStreams, or from OpenAPI specs. Quickly scaffold types and properties into a ready-to-use PHP codebase for APIs and domain models.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Schema.org/ActivityStreams/OpenAPI Alignment: The package excels at generating PHP classes from structured vocabularies (Schema.org, ActivityStreams, OpenAPI), making it ideal for projects requiring semantic interoperability (e.g., knowledge graphs, Linked Data, or API-first architectures). It aligns well with API Platform’s core philosophy of leveraging standardized schemas for API design.
  • Doctrine ORM/ODM Integration: Deep support for Doctrine (including inheritance, embeddables, and custom column configurations) ensures seamless integration with Laravel’s Eloquent (via Doctrine Bridge) or standalone Doctrine projects. For pure Laravel, this requires Eloquent-to-Doctrine mapping (e.g., using doctrine/orm alongside Eloquent).
  • API Platform Core Compatibility: Generates PHP 8 attributes (e.g., [ApiResource], [ApiProperty]) and security annotations, which are directly usable in API Platform. For Laravel, this would require API Platform’s Laravel adapter or manual attribute mapping (e.g., via api-platform/core + nelmio/api-doc-bundle).
  • Extensibility: Supports custom Twig templates, YAML/OWL/XML Schema inputs, and OpenAPI/Swagger, enabling tailored generation for niche use cases (e.g., generating models from internal domain-specific schemas).

Integration Feasibility

  • Laravel Ecosystem:
    • Pros:
      • Works with Symfony 7/PHP 8.4 (Laravel 10+ compatible).
      • Can generate Eloquent-compatible models if Doctrine configurations are mapped to Eloquent (e.g., using doctrine/dbal + custom traits).
      • Supports DTOs (useful for Laravel’s API resources or Form Requests).
    • Cons:
      • No native Eloquent support: Requires manual adaptation (e.g., replacing Doctrine annotations with Eloquent attributes like #[Column]protected $attribute).
      • API Platform integration: Laravel lacks native API Platform support; would need custom middleware (e.g., api-platform/core + symfony/ux-live-component for hybrid setups).
  • Non-Laravel PHP:
    • Native fit for Symfony/API Platform projects. For Laravel, the package is better suited for code generation (e.g., bootstrapping a project) rather than runtime use.

Technical Risk

  • Schema Evolution: Schema.org/ActivityStreams are frequently updated. The package’s embedded schemas mitigate offline risks, but custom vocabularies may require manual updates.
  • Attribute Mapping:
    • Laravel’s Eloquent uses different annotations/attributes than Doctrine (e.g., #[Column] vs. #[ORM\Column]). Risk: Generated classes may need post-processing (e.g., via php-cs-fixer or custom scripts).
    • API Platform attributes (#[ApiResource]) are Symfony-specific; Laravel would need polyfills or alternative annotations (e.g., #[AsApiResource] via custom packages).
  • Performance:
    • Generating large schemas (e.g., full Schema.org) may bloat the codebase. Mitigation: Use partial generation (e.g., generate --types="Person,Product").
    • PHAR vs. Composer: The PHAR version avoids dependency conflicts but may lag behind the Composer version.

Key Questions

  1. Primary Use Case:
    • Is this for bootstrapping a Laravel API (e.g., generating models from Schema.org) or runtime schema validation (e.g., enforcing OpenAPI contracts)?
    • If the latter, consider alternatives like zircote/swagger-php or spatie/laravel-openapi.
  2. Attribute Compatibility:
    • How will Doctrine attributes (e.g., #[ORM\ManyToOne]) map to Eloquent? Will a custom trait or model generator bridge the gap?
  3. API Platform in Laravel:
    • Is API Platform’s Symfony-centric nature a blocker? If so, explore Laravel-specific alternatives like filp/whoops for API docs or darkaonline/l5-swagger for OpenAPI.
  4. Maintenance Overhead:
    • Will the generated code require manual tweaks (e.g., adding Laravel-specific logic like #[UniqueRule] or #[HasMany])? If so, factor in CI/CD steps for post-generation fixes.
  5. Schema Customization:
    • Are there domain-specific schemas beyond Schema.org/ActivityStreams? The package supports custom OWL/XML, but validation/testing may be needed.

Integration Approach

Stack Fit

Component Fit Level Notes
Laravel Eloquent Medium Doctrine attributes require mapping (e.g., #[ORM\Column]protected $field).
Symfony API Platform High Native support for #[ApiResource], #[ApiProperty], etc.
OpenAPI/Swagger High Direct OpenAPI input support; generated classes can be used with darkaonline/l5-swagger.
Schema.org/ActivityStreams High Core functionality aligns perfectly.
Custom Vocabularies Medium Requires OWL/XML Schema input; validation may be needed.
Laravel Fortify/Passport Low No direct integration; would need manual attribute mapping (e.g., #[ApiProperty(security="is_granted('auth')")]).

Migration Path

  1. Pilot Phase (Bootstrapping):
    • Use the package to generate a subset of models (e.g., Person, Product) from Schema.org/OpenAPI.
    • Test compatibility with Laravel Eloquent by:
      • Replacing Doctrine attributes with Eloquent equivalents (e.g., #[ORM\Column]protected $name).
      • Using traits to unify Doctrine/Eloquent logic (e.g., HasSchemaProperties).
    • Example workflow:
      vendor/bin/schema generate --types="Person" --output="app/Models/Schema" --config="config/schema.yaml"
      
  2. Hybrid Integration:
    • For API Platform in Laravel, use:
      • api-platform/core (Symfony bundle) + spatie/laravel-symfony-support for Symfony interop.
      • Alternative: Generate OpenAPI specs first, then use darkaonline/l5-swagger for Laravel.
    • For pure Laravel, treat generated classes as DTOs or base models, extending them with Laravel-specific logic.
  3. Full Adoption:
    • Automate generation in CI/CD (e.g., GitHub Actions) to regenerate models on schema updates.
    • Use custom templates to enforce Laravel conventions (e.g., #[HasFactory] in generated models).

Compatibility

  • Symfony 7 / PHP 8.4: Fully compatible with Laravel 10+.
  • Doctrine ORM: Requires doctrine/dbal or doctrine/orm alongside Eloquent (not natively supported).
  • API Platform: Needs Symfony integration (not native to Laravel). Consider:
    • Option 1: Use API Platform for backend services, Laravel for frontend logic.
    • Option 2: Generate OpenAPI specs, then use l5-swagger for Laravel API docs.
  • Laravel-Specific Packages:
    • Sanctum/Passport: No direct support; may need custom attributes (e.g., #[ApiProperty(security="is_granted('auth')")]).
    • Scout/Spatie Media Library: Generated models can be extended to include these traits.

Sequencing

  1. Define Scope:
    • Decide if generating full schemas (e.g., all Schema.org) or subset (e.g., only Product/Event).
  2. Configure:
    • Create config/schema.yaml to customize:
      • Namespace prefixes (e.g., App\Models\Schema).
      • Doctrine/Eloquent attribute mappings.
      • OpenAPI/Swagger input files.
  3. Generate:
    • Run vendor/bin/schema generate with target types/config.
  4. Adapt:
    • Post-process generated files to:
      • Replace Doctrine attributes with Eloquent equivalents.
      • Add Laravel-specific logic (e.g., #[UniqueRule], #[HasMany]).
  5. Integrate:
    • For API Platform: Set up Symfony interop (e.g., spatie/laravel-symfony-support).
    • For pure Laravel: Use generated models as DTOs or base classes.
  6. Automate:
    • Add generation to CI/CD (e.g., trigger on composer install).

Operational Impact

Maintenance

  • Schema Updates:
    • Proactive: Monitor Schema.org/ActivityStreams
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor