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

Swagger Ui Laravel Package

swagger-api/swagger-ui

Swagger UI renders interactive API docs from your OpenAPI (Swagger) spec, letting teams and consumers explore endpoints without implementation details. Available as npm packages (swagger-ui, swagger-ui-dist) and Docker for easy hosting and bundling.

View on GitHub
Deep Wiki
Context7

Swagger UI is a web-based interface for visualizing and interacting with APIs from an OpenAPI (Swagger) specification. It generates live, human-friendly documentation that helps teams validate endpoints, try requests in-browser, and share a consistent contract with consumers—without needing application code in place.

Distributed as swagger-ui, swagger-ui-dist, and related builds, it’s easy to embed in SPAs or serve as static assets alongside your API.

  • Renders interactive docs directly from OpenAPI 2.0/3.x
  • “Try it out” requests with parameter and response previews
  • Bundled dist package for dependency-free hosting
  • Customizable UI (themes, plugins, layout options)
  • Works well with CI/CD and containerized deployments
Frequently asked questions about Swagger Ui
How do I integrate Swagger UI with a Laravel API that uses darkaonline/l5-swagger for OpenAPI docs?
First, generate your OpenAPI spec using `php artisan l5-swagger:generate`. Then, place the `swagger-ui-dist` files in Laravel’s `public/swagger-ui` folder. Reference the spec in Swagger UI’s config via `url: '/api/swagger.json'` in the HTML file. Ensure your Laravel API routes are properly annotated for OpenAPI compatibility.
Can Swagger UI work with Laravel’s built-in API authentication (e.g., Sanctum or Passport)?
Yes, but you’ll need to configure OAuth2 in Swagger UI’s JavaScript initialization. Use `initOAuth` to set up OAuth2 client credentials, but avoid hardcoding secrets—use environment variables or a proxy like Laravel Passport. For API tokens, use the `Authorization` header in Swagger UI’s request editor.
What’s the best way to deploy Swagger UI for a Laravel API in production?
For minimal overhead, serve `swagger-ui-dist` from Laravel’s `public` folder. For isolation, deploy it separately via Docker (`swaggerapi/swagger-ui`) or a static host like Netlify. If using SPAs, bundle `swagger-ui` via Laravel Mix. Always validate CORS settings if Swagger UI runs on a different domain.
Does Swagger UI support OpenAPI 3.1, and will it work with Laravel APIs using zircote/swagger-php?
Swagger UI primarily supports OpenAPI 3.0.x, with partial 3.1 support. Ensure your Laravel API’s spec (generated via `zircote/swagger-php` or `l5-swagger`) uses `openapi: 3.0.3` for broad compatibility. Test the spec using tools like `openapi-tools/openapi-generator` before deploying.
How can I customize Swagger UI’s appearance to match my Laravel app’s branding?
Use Swagger UI’s `dom_id` and `layout` options to inject custom CSS or themes. Override the default stylesheet by adding a `<style>` tag in the HTML file or linking an external CSS file. For deeper customization, extend the `SwaggerUIBundle` in your Laravel Mix setup or use plugins like `SwaggerUIStandalonePreset`.
Is there a performance impact if I include Swagger UI in a Laravel SPA built with Vue/React?
The `swagger-ui` npm package (~2MB gzipped) adds minimal overhead for SPAs. Use `swagger-ui-dist` for static docs to avoid bundling dependencies. Lazy-load Swagger UI or host it separately to reduce initial load time. Monitor bundle size with tools like `webpack-bundle-analyzer` if performance is critical.
How do I test Swagger UI’s functionality in a Laravel CI/CD pipeline?
Add a post-deployment test using tools like Nightwatch.js or Selenium to verify deep linking, request/response cycles, and OAuth2 flows. Mock API responses if needed, or use Laravel’s `Http::fake()` to simulate endpoints. Ensure your OpenAPI spec is validated in the pipeline using `openapi-tools/openapi-generator`.
What are the alternatives to Swagger UI for Laravel API documentation?
For simpler docs, consider `redocly/redoc` (markup-focused) or Postman’s OpenAPI import. If you need API testing without UI, use `openapi-tools/openapi-generator` to create SDKs. For Laravel-specific tools, `darkaonline/l5-swagger` includes built-in UI options, though they’re less customizable than Swagger UI.
How do I secure Swagger UI in production to prevent abuse (e.g., DDoS from repeated API calls)?
Restrict access via Laravel middleware (e.g., `auth:api` or IP whitelisting). For OAuth2-protected APIs, ensure Swagger UI’s `initOAuth` uses short-lived tokens. Add rate limiting via Laravel’s `throttle` middleware or a reverse proxy like Nginx. Avoid exposing Swagger UI to public internet if the API is sensitive.
Can I use Swagger UI with Laravel Octane or Lumen for high-performance APIs?
Yes, Swagger UI is stateless and works with any Laravel-compatible API. For Octane, serve the `swagger-ui-dist` files via Octane’s static file handling or a separate web server. For Lumen, place the files in `public/swagger-ui` and configure CORS if needed. Both setups support OpenAPI specs generated by `l5-swagger` or `zircote/swagger-php`.
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
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
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