Can't generate API documentation in l5-swagger

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Troubleshooting API Documentation Generation Issues with L5-Swagger in Laravel 5 Introduction Genrating API documentation using tools like L5-Swagger for your Laravel 5 application can save a lot of time and effort in documenting your code. However, you may encounter various issues while generating your API documentation. In this article, we will discuss some common problems that arise during the process and provide solutions to resolve them. Solution 1: Missing @OA\Info() Issue The exception "Required @OA\Info() not found" is a common issue when attempting to generate API documentation with L5-Swagger in Laravel 5. This can be caused by several reasons, such as incorrect dependencies, improper code placement, or lack of the required namespace. Here are some steps you can follow to troubleshoot and fix this problem: 1. Install the necessary dependency: Run "composer require zircote/swagger-php" in your Laravel project's terminal to install the swagger-php library. 2. Check your namespace usage: Make sure that you have included both the 'OpenApi\\' and 'Zircote\SwaggerPHP\Bundle\SwaggerBundle\\' namespaces within your code. For example, adding "use OpenApi\Annotations as OA; use Zircote\SwaggerPHP\Bundle\SwaggerBundle\\" at the beginning of your controller class will help resolve this issue. 3. Ensure correct API definition placement: Place your API documentation definition in a file named 'documentation.php'. Create this file and place it within the 'app' directory, where you should also have 'AppServiceProvider.php', 'routes/web.php', and 'Config\RouteServiceProvider.php' files. Solution 2: Fetch Error Not Found for API Documents If your localhost server shows an "Error Not Found http://localhost:8081/docs/api-docs.json" message, it means that either the API documentation is not being generated properly or there is a mistake in the URL used to access the documentation. To resolve this issue, try the following steps: 1. Check your configuration file: Ensure the correct environment variable for your Laravel 5 application is set as 'local' to allow localhost access. In the ".env" file, make sure the line "APP_ENV=production" or any other non-local value is not configured. 2. Update the server URL in documentation.php: Modify the first 'basePath' variable in your 'documentation.php' file to reflect the correct domain name and port for your localhost setup (e.g., "basePath => 'http://localhost:8081'"). 3. Regenerate API documentation: Use the command 'php artisan l5-swagger:generate' in your Laravel project's terminal to rebuild your API documentation. Conclusion Generating API documentation for your Laravel 5 application can be a crucial step towards ensuring its smooth functioning and understanding by other developers. By following best practices, properly configuring your application, and employing necessary tools like L5-Swagger, you can solve common issues that arise during the process. In case of further difficulties, always remember to consult official documentation or reach out to experts for assistance.