Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger - "Required @OA\Info() not found"

I just got into api documentation and tried to use Swagger

here is my php file with routes that I want to document:

<?php

use OpenApi\Annotations as OA;

/**
 * @OA\Info(title="My First API", version="0.1")
 */
return [
    /**
     * @OA\Get(
     *     path="/api/v1/test",
     *     @OA\Response(response="200", description="An example resource")
     * )
     */
    'GET api/v1/test' => 'test/index',
];

But when I run ./vendor/bin/openapi api/config/routes.php cli only outputs errors:

Warning: Required @OA\Info() not found
Warning: Required @OA\PathItem() not found
openapi: 3.0.0

I then tried Swagger2 and it worked just fine

Im using php8.1 from php:8.1-fpm-alpine docker image, the latest zircote/swagger-php package and the Yii2 framework

like image 708
ddruganov Avatar asked Oct 18 '25 12:10

ddruganov


1 Answers

Here is solution https://github.com/DarkaOnLine/L5-Swagger/issues/443

Add in your base Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

/**
 * @OA\Info(title="My First API", version="0.1")
 */
class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
like image 130
Firdavs Avatar answered Oct 21 '25 01:10

Firdavs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!