'L5-swagger api documentation: Getting error Required @OA\PathItem() not found

After reading these 2 posts here on Stackoverflow: How to Solved ErrorException : Required @OA\PathItem() not found Can't generate API documentation in l5-swagger

I still get an error Required @OA\PathItem() not found after running php artisan l5-swagger:generate.

This is my Controller.php part:

/**
 * @OA\Info(
 *     title="My First API Documentation",
 *     version="0.1",
 *      @OA\Contact(
 *          email="[email protected]"
 *      ),
 * ),
 *  @OA\Server(
 *      description="Learning env",
 *      url="https://foo.localhost:8000/api/"
 *  ),
 */
class Controller extends BaseController
{

and this is my ProfileController part:

   /**
     * @OA\Get(
     *      path="/profiles",
     *      @OA\Response(
     *          response=200,
     *          description="Successful operation",
     *      ),
     *     @OA\PathItem (
     *     ),
     * )
     */
   function index()
    {
        return new ProfileCollection(Profile::with('user')->paginate());
    }

What am I overlooking here? If anyone can explain and help that would be great :)

EDIT - SOLUTION

The problem occured because I am using a laravel modules package and I had to change a bit of code in the l5-swagger.php config file:

'annotations' => [
                    base_path('Modules/Api/Http'), <-- changed the base path to the correct module
                ],

I then copied the main Controller.php from App/Http/Controllers to the same Module to also get rid of the occuring @OA\Info() not found error after that.



Solution 1:[1]

As per migration documentation you need to import Annotations class use OpenApi\Annotations as OA; that will fix your problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Veshraj Joshi