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

Laravel Openapi Cli Laravel Package

spatie/laravel-openapi-cli

Generate Laravel Artisan commands from any OpenAPI spec. Each endpoint becomes a CLI command with typed options for path/query params and request bodies. Configure base URL, auth, caching, output formats, redirects, and custom error handling—great with Laravel Zero.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The package excels in API-first development by bridging OpenAPI specs (Swagger/OAS) with Laravel’s CLI ecosystem. Ideal for teams using contract-first design, AI-driven API documentation, or automated API testing.
  • Leverage Points:
    • Artisan Command Generation: Converts OpenAPI specs into executable CLI commands, enabling interactive API exploration (e.g., php artisan api:call /users).
    • AI Agent Integration: Lowers friction for AI tools (e.g., LangChain, Hugging Face) to discover and invoke APIs via CLI.
    • Package-Level Support: Works in Laravel packages, enabling reusable API contracts across microservices.
  • Anti-Patterns:
    • Not suited for non-API Laravel apps (e.g., admin panels, SaaS platforms without public APIs).
    • Requires maintained OpenAPI specs—garbage in, garbage out for command generation.

Integration Feasibility

  • Laravel Compatibility:
    • Minimal Overhead: Single Composer package (spatie/laravel-openapi-cli) with zero config for basic usage. Requires:
      • Laravel 10.x+ (PHP 8.1+).
      • OpenAPI spec file (YAML/JSON) in config/openapi.php or custom path.
    • Extensibility: Supports custom command logic via event listeners or service providers.
  • Dependencies:
    • Core: Uses spatie/laravel-package-tools (for package bootstrapping) and symfony/console.
    • OpenAPI Parsing: Relies on zircote/swagger-php (lightweight, no heavyweight tools like Swagger UI).
  • Testing:
    • Unit/Feature Tests: Package includes CI/CD (GitHub Actions) with test coverage, but no end-to-end tests for edge cases (e.g., complex OpenAPI specs with $refs).

Technical Risk

Risk Area Severity Mitigation Strategy
Spec Parsing Errors High Validate OpenAPI specs with spectral or swagger-cli pre-integration.
Command Bloat Medium Use --filter CLI flags to generate only needed endpoints.
AI Agent Misuse Medium Document rate-limiting and auth requirements in generated commands.
Laravel Version Lock Low Package supports LTS Laravel versions; monitor deprecations.
Custom Logic Gaps Low Extend via OpenApiCommand events or override default behavior.

Key Questions

  1. OpenAPI Spec Quality:
    • Are specs machine-readable (e.g., no manual annotations, consistent $ref usage)?
    • How will schema evolution (e.g., breaking changes) be handled?
  2. Use Case Clarity:
    • Is this for internal tooling, public API docs, or AI agent orchestration?
    • Will commands replace or complement existing API clients (e.g., Guzzle, Postman)?
  3. Performance:
    • Will generated commands cache API responses (e.g., for testing) or hit live endpoints?
  4. Security:
    • How will authentication (e.g., API tokens, OAuth) be handled in generated commands?
  5. Maintenance:
    • Who owns spec updates (devs, PMs, or a dedicated API team)?

Integration Approach

Stack Fit

  • Best For:
    • Laravel Monoliths/Microservices: Centralized API contracts with shared OpenAPI specs.
    • AI/ML Pipelines: Enable non-dev users (e.g., data scientists) to call APIs via CLI.
    • Developer Experience: Replace curl/Postman with Laravel-native commands (e.g., php artisan api:fetch /orders --limit=10).
  • Stack Constraints:
    • PHP 8.1+ Required: May block legacy Laravel 8.x apps.
    • OpenAPI Tooling: Assumes existing swagger-php or openapi-generator in the pipeline.
    • No Frontend Impact: Pure backend tool; UI teams unaffected.

Migration Path

  1. Assessment Phase:
    • Audit existing API specs (YAML/JSON) for compatibility with spatie/laravel-openapi-cli.
    • Identify high-value endpoints to prioritize for CLI generation.
  2. Pilot Integration:
    • Install package: composer require spatie/laravel-openapi-cli.
    • Configure config/openapi.php to point to spec files.
    • Test with php artisan openapi:generate (dry run).
  3. Gradual Rollout:
    • Phase 1: Generate commands for internal tools (e.g., data export scripts).
    • Phase 2: Expose to AI agents via documented CLI interface.
    • Phase 3: Replace legacy API clients (e.g., custom PHP scripts) with generated commands.
  4. Fallback Plan:
    • If spec parsing fails, fall back to manual Artisan commands or symfony/process wrappers.

Compatibility

Component Compatibility Notes
Laravel Tested on 10.x; may need tweaks for 9.x (PHP 8.0).
OpenAPI Specs Supports OAS 2.0/3.0/3.1; complex specs (e.g., dynamic $refs) may need tuning.
AI Agents Works with tools like LangChain or Hugging Face via CLI execution.
CI/CD Can be gated in PRs to validate OpenAPI specs before merging.
Monorepos Supports package-level specs (e.g., vendor/package/openapi.yaml).

Sequencing

  1. Pre-Requisites:
    • Maintained OpenAPI spec (YAML/JSON).
    • Laravel 10.x+ with PHP 8.1+.
    • Basic Artisan familiarity in the team.
  2. Core Integration:
    • Install package and configure config/openapi.php.
    • Generate commands: php artisan openapi:generate.
    • Test commands in a staging environment.
  3. Advanced Customization:
    • Extend commands via OpenApiCommand events.
    • Add auth middleware to generated commands.
  4. Documentation:
    • Publish CLI reference for AI agents (e.g., --help output).
    • Add to internal dev portal (e.g., Notion, Confluence).

Operational Impact

Maintenance

  • Pros:
    • Low Ongoing Effort: Once specs are in place, commands auto-generate.
    • Spec-Driven: Changes to APIs automatically update CLI (if specs are kept sync’d).
    • No Runtime Overhead: Commands are lazy-loaded (no impact on API performance).
  • Cons:
    • Spec Maintenance: Breaking changes in OpenAPI require command updates.
    • Deprecation Risk: If spatie/laravel-openapi-cli is abandoned, fork or rewrite may be needed.
  • Ownership:
    • API Team: Owns OpenAPI specs and command correctness.
    • DevOps: May need to cache generated commands in CI/CD.

Support

  • Troubleshooting:
    • Common Issues:
      • InvalidOpenApiSpecException: Spec validation fails (fix with spectral lint).
      • CommandNotFoundException: Spec path misconfigured in config/openapi.php.
    • Debugging Tools:
      • php artisan openapi:generate --verbose for detailed parsing logs.
      • php artisan openapi:validate to check spec health.
  • Escalation Path:
    • L1: Devs use --help and package docs.
    • L2: Check GitHub issues for known spec parsing quirks.
    • L3: Fork and extend if core functionality is missing.

Scaling

  • Performance:
    • Command Generation: O(1) for simple specs; O(n) for deeply nested $refs (mitigate with --filter).
    • Execution: Each CLI call hits the live API (add caching for testing).
  • Team Scaling:
    • Enables Non-Devs: Data scientists/analysts can call APIs without code.
    • Reduces Toil: Eliminates manual curl scripts for common API tasks.
  • Horizontal Scaling:
    • Stateless: No impact on Laravel app scaling.
    • Spec Reuse: Share OpenAPI specs across **multiple
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests