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 an OpenAPI spec. Each API endpoint becomes its own command with typed options for params and request bodies, plus auth, base URL, caching, redirects, and output formatting—ideal for building API CLIs with Laravel Zero.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-Native Integration: Designed for Laravel’s Artisan ecosystem, leveraging service providers, facades, and command registration. Fits seamlessly into Laravel’s modular architecture (e.g., register() in a service provider).
  • OpenAPI-Centric: Translates OpenAPI specs into executable CLI commands, reducing manual mapping of endpoints to CLI logic. Ideal for API-first development where specs are authoritative.
  • Command-Oriented: Generates one command per API endpoint, with typed parameters for path/query/body inputs. Aligns with Laravel’s CLI tooling patterns (e.g., php artisan command:name).
  • Composability: Supports chaining configuration methods (e.g., ->auth()->cache()->retryOn()), enabling fluent, declarative setup—similar to Laravel’s HTTP client or queue workers.
  • Laravel Zero Synergy: Explicitly built for Laravel Zero, enabling standalone CLI tools without Laravel’s full stack. Useful for microservices or internal tools.

Integration Feasibility

  • Low Friction: Requires only:
    1. OpenAPI spec (YAML/JSON) for the target API.
    2. Laravel project (or Laravel Zero app) with HTTP client (e.g., Guzzle, Symfony HTTP).
    3. Basic configuration in a service provider.
  • Dependency Light: Adds minimal overhead (core package + Guzzle/Symfony HTTP). No database or heavy runtime dependencies.
  • Spec Flexibility: Works with public/private APIs, including those requiring auth (OAuth, API keys, basic auth). Supports dynamic auth via closures (e.g., token refresh).
  • Output Customization: Supports JSON, YAML, or HTML output, and can integrate with Laravel’s logging or notification systems.

Technical Risk

  • Spec Quality Dependency: Reliability hinges on accurate, complete OpenAPI specs. Incomplete specs (e.g., missing parameters, deprecated endpoints) may generate broken commands.
  • Parameter Handling: Complex OpenAPI schemas (e.g., nested objects, arrays) may require manual adjustments to command arguments (e.g., --input '{"nested":{...}}').
  • Auth Complexity: Dynamic auth (e.g., OAuth token refresh) requires custom closures, adding minor implementation risk for edge cases (e.g., retry logic failures).
  • Caching Trade-offs: Spec caching (TTL-based) improves performance but risks stale commands if specs change frequently. Requires monitoring for spec updates.
  • Laravel Zero Limitations: Standalone CLI tools may need additional setup (e.g., environment config, dependency injection) compared to full Laravel apps.

Key Questions

  1. Spec Maturity:
    • Are OpenAPI specs for target APIs up-to-date and comprehensive? If not, how will gaps be addressed (e.g., manual overrides)?
    • Who owns spec maintenance? Will CLI commands break if specs change without updates?
  2. Use Case Alignment:
    • Are commands primarily for internal tools, CI/CD, or end-user CLI apps? This affects error handling, auth, and output needs.
    • Will users need custom logic beyond HTTP requests (e.g., local file processing)? If so, how will commands be extended?
  3. Performance:
    • How frequently will specs be updated? Is caching (TTL) acceptable, or are real-time spec fetches needed?
    • Will commands be used in high-frequency scenarios (e.g., loops in scripts)? If so, caching and retry logic must be optimized.
  4. Error Handling:
    • Are there standardized error responses for APIs? The package supports custom hooks (e.g., rate limiting), but generic errors may need global handling.
    • Should failures trigger notifications (e.g., Slack, email) or integrate with Laravel’s exception handling?
  5. Scaling:
    • How many APIs/commands will be registered? Large specs may bloat the command list; consider namespacing or grouping.
    • Will commands be shared across teams? If so, document registration patterns (e.g., environment-specific specs).
  6. Testing:
    • How will commands be tested? The package supports unit testing, but integration tests may require mocking HTTP responses.
    • Are there mocking strategies for auth, retries, or error scenarios?
  7. Laravel Zero vs. Laravel:
    • If using Laravel Zero, how will dependencies (e.g., auth managers) be injected? Zero’s minimalism may require custom bootstrapping.
    • For full Laravel apps, will commands be exposed via Artisan or a custom facade?

Integration Approach

Stack Fit

  • Laravel Core: Leverages Artisan commands, service providers, and facades. No conflicts with Laravel’s architecture.
  • HTTP Clients: Works with Guzzle or Symfony HTTP (included in Laravel). No vendor lock-in.
  • Auth Systems: Integrates with Laravel’s auth (e.g., Sanctum, Passport) or custom token managers. Supports OAuth, API keys, and basic auth.
  • Laravel Zero: Explicitly designed for Zero’s CLI-first paradigm. Enables building APIs-as-CLI-tools without a web server.
  • Testing Tools: Compatible with Laravel’s testing (e.g., HTTP tests, mocking Guzzle). Supports PEST/PHPUnit.

Migration Path

  1. Assess Specs:
    • Audit target OpenAPI specs for completeness (endpoints, parameters, auth).
    • Identify gaps requiring manual overrides (e.g., custom parameters).
  2. Setup:
    • Install package: composer require spatie/laravel-openapi-cli.
    • Publish config (if needed): php artisan vendor:publish --provider="Spatie\OpenApiCli\OpenApiCliServiceProvider".
  3. Register APIs:
    • Configure in a service provider (e.g., AppServiceProvider):
      OpenApiCli::register('https://api.example.com/openapi.yaml', 'api')
          ->auth(fn () => auth()->user()->apiToken)
          ->cache(ttl: 3600);
      
  4. Extend (Optional):
    • Customize commands via traits or override generated classes.
    • Add global error handlers or middleware.
  5. Test:
    • Validate commands with php artisan api:list and sample requests.
    • Test auth, retries, and edge cases (e.g., 429 responses).
  6. Deploy:
    • Integrate into CI/CD (e.g., php artisan api:process-invoices in workflows).
    • Document commands for non-engineers (e.g., api:list --help).

Compatibility

  • Laravel Versions: Supports Laravel 8+ (check Spatie’s Laravel policy).
  • PHP Versions: Requires PHP 8.0+. No major version conflicts.
  • OpenAPI Versions: Supports OpenAPI 2.0 and 3.x specs. Validate specs with tools like Swagger Editor.
  • Non-Laravel PHP: Can be adapted for non-Laravel projects by manually bootstrapping dependencies (e.g., Guzzle, Symfony components). Not officially supported.
  • IDE Support: Generates commands with typed parameters, improving IDE autocompletion (e.g., --param-name=VALUE hints).

Sequencing

  1. Phase 1: Pilot API
    • Start with one well-documented API (e.g., a stable internal service).
    • Register 3–5 critical endpoints as commands (e.g., api:fetch-orders, api:create-user).
    • Test with a small team (e.g., QA or support).
  2. Phase 2: Expand
    • Add more APIs or endpoints, grouping by domain (e.g., payments:, inventory:).
    • Implement custom auth or error handling for complex APIs.
  3. Phase 3: Integrate
    • Embed commands in CI/CD pipelines or internal scripts.
    • Document commands in a runbook or wiki for non-engineers.
  4. Phase 4: Optimize
    • Adjust caching, retries, or output formats based on usage patterns.
    • Explore Laravel Zero for standalone CLI tools (e.g., php mycli:process-data).

Operational Impact

Maintenance

  • Spec-Driven Updates: Commands auto-update when specs change. Monitor specs for:
    • Deprecated endpoints (remove unused commands).
    • Breaking changes (e.g., renamed parameters).
  • Configuration Management:
    • Centralize API registrations in a single service provider or config file.
    • Use environment variables for dynamic settings (e.g., API_BASE_URL).
  • Dependency Updates:
    • Monitor Spatie’s releases for Laravel/OpenAPI spec compatibility.
    • Update Guzzle/Symfony HTTP if security patches are released.
  • Command Lifecycle:
    • Deprecate commands gracefully (e.g., warn users before removing endpoints).
    • Archive old commands in a legacy/ namespace if needed.

Support

  • Troubleshooting:
    • Common issues:
      • Broken commands: Spec errors (validate with openapi-cli validate).
      • Auth failures: Check token managers or closures.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata