Weave 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 To Swagger Laravel Package

riconijeboer/laravel-to-swagger

laravel-to-swagger generates Swagger/OpenAPI documentation for Laravel applications, turning routes and controllers into browsable API docs so your specification stays aligned with the code you ship.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install with composer require riconijeboer/laravel-to-swagger. Because the package is archived (last release Feb 2022), pin your Laravel/PHP versions first — it predates Laravel 10/11, so expect dependency conflicts on modern apps. Safest on Laravel 8 or 9.
  • Publish the config (php artisan vendor:publish --tag=swagger-config, or check the package README for the exact tag) and open config/swagger.php first. That file is the source of truth for the generated OpenAPI document — info block, servers, tags, security schemes, and the paths/components arrays.
  • Define one endpoint in the config as a smoke test: a GET /api/ping with a 200 response schema. Run the package's generate command (typically php artisan swagger:generate or similar) and confirm a valid openapi: 3.0.x JSON/YAML lands in the configured output path.
  • Point Swagger UI at the generated file. This package produces the spec, not necessarily the UI — pair it with l5-swagger or any static Swagger UI if you need a browser view. That pairing is the first real use case: one config file → one generated JSON → one browsable doc.
  • Look at the package's src/ for the generator class and any Swagger facade early. With a small, archived package you'll rely on reading source rather than docs.

Implementation Patterns

  • Config-as-contract. Treat config/swagger.php as the API contract. Because the spec is authored in PHP arrays rather than annotations, it reviews well in PRs and diffs cleanly. Keep route definitions in Laravel and the OpenAPI paths side-by-side in the same PR.
  • Split and merge. For anything beyond a handful of endpoints, don't grow one giant config file. Keep per-domain partials (swagger/auth.php, swagger/users.php) and merge them in a service provider or custom command before generation. The package's config array is just PHP — array_merge_recursive or data_get/Arr::set works fine.
  • Generate in CI, serve statically in production. Run the generate command in your build pipeline (or a deploy hook), commit or artifact the JSON, and serve it as a static file. Never generate per-request. This is the single biggest performance and reliability win with this class of package.
  • Reuse components aggressively. Define components.schemas.User, components.responses.NotFound, components.securitySchemes.bearerAuth once and $ref them. This keeps the generated file small and makes codegen (openapi-generator, orval) usable downstream.
  • Align path params with routes. Use the exact Laravel parameter name (/users/{user} not /users/{id}) so generated clients and Laravel's route model binding agree. This is the most common source of drift between the spec and the app.
  • Validate in CI. Pipe the generated spec through swagger-cli validate or Spectral. A malformed $ref or a missing responses block silently produces a file that breaks client generators.
  • Integrate with tests lightly. If you have feature tests, assert that every registered API route appears in the generated spec (route name ↔ path map). It's a cheap guard against undocumented endpoints.

Gotchas and Tips

  • Archived means frozen. No fixes for Laravel 10/11, PHP 8.2+, or OpenAPI 3.1. If you're on a modern stack, budget time to fork it or migrate to dedoc/scramble or knuckleswtf/scribe. With 22 stars, community answers are scarce — you are the maintainer.
  • OpenAPI 3.0.x vs 3.1. The output is 3.0-era. Tools like Stoplight and some client generators still prefer 3.0, so this is often fine — but don't hand-write 3.1 constructs (type: ["string","null"]) into the config; they'll be ignored or rejected.
  • config:cache will freeze your spec inputs. If the config pulls from env() or runtime values, resolve them at generation time, not in the config file, or your cached config will bake stale values into the spec. Prefer generating from a dedicated command or service that reads fresh data.
  • Command registration. In older packages the Artisan command is registered via Kernel::$commands rather than auto-discovery. If php artisan list doesn't show it, check src/Console and register manually.
  • Path ordering and wildcards. OpenAPI consumers are picky about overlapping paths (/users/{id} vs /users/me). Order matters in some tooling; document the more specific one and rely on Laravel's route ordering to match.
  • Nullable and required are independent. In the config you must set both nullable: true and omit the property from required if it's optional. Forgetting one produces confusing generated clients.
  • Debug by validating, not by eyeballing. npx @apidevtools/swagger-cli validate storage/app/swagger.json catches 90% of "the UI shows nothing" issues. Swagger UI failing to render is almost always a $ref typo or a mis-indented array in the config.
  • Extension point is the config array itself. With no plugin system worth relying on, the practical extension strategy is: wrap the generator in your own Artisan command, post-process the array before serialization, and keep the package as a thin serializer. That gives you a migration path off it later without rewriting your spec.
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.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource