DarkaOnLine / L5-Swagger

OpenApi or Swagger integration to Laravel
https://github.com/DarkaOnLine/L5-Swagger
MIT License
2.64k stars 394 forks source link

Legacy feature | Is Swagger not reading annotation other then controller file? #613

Closed semudassarzahid closed 1 month ago

semudassarzahid commented 2 months ago

Description:

Hi community, I have an issue regarding usage of this package. Requirement is that I want to not write the docs in any Controller file of Laravel. So, I create a new file of PHP is /app directory of Laravel. Swagger should scan those annotations from that file. Previously, that was working for this darkaonline/swagger-lume@5.6.1.

Steps To Reproduce:

What I did in it, First I added base file like app/docs/base.php

<?php

/**
 * @OA\OpenApi(
 *   @OA\Info(
 *     title="Project Name",
 *     version="1.0.0",
 *     description="API Documentation for Application",
 *     @OA\Contact(
 *       email="demo@domain.com",
 *       name="Support Team"
 *     )
 *   )
 * )
 */

then I added a another file app/docs/blog/component.php

<?php

/**
 * @OA\Schema(
 *     schema="Blog",
 *     type="object",
 *     title="Blog",
 *     @OA\Property(property="id", type="integer", example=1),
 *     @OA\Property(property="name", type="string", example="Blog Title"),
 * )
 */

then I added a another file app/docs/blog/index.php

<?php

/**
     * @OA\Get(
     *     path="/blog",
     *     summary="Get blog posts",
     *     @OA\Response(
     *         response=200,
     *         description="Successful operation",
     *         @OA\JsonContent(
     *             type="array",
     *             @OA\Items(ref="#/components/schemas/BlogPost")
     *         )
     *     )
     * )
     */

So, it is not generating the docs and giving me error like Required @OA\PathItem() not found

on other side, if I move same docs into controller, it start working fine like

...
class BlogController extends Controller
{
/**
     * @OA\Get(
     *     path="/blog",
     *     summary="Get blog posts",
     *     @OA\Response(
     *         response=200,
     *         description="Successful operation",
     *         @OA\JsonContent(
     *             type="array",
     *             @OA\Items(ref="#/components/schemas/BlogPost")
     *         )
     *     )
     * )
     */
public function index(){}

your response will be appreciated, I am using this library after a long time. Thank you!

DerManoMann commented 2 months ago

Could be this one: https://zircote.github.io/swagger-php/guide/faq.html#warning-required-oa-info-not-found