Laravel swagger annotations into a separate file

832 views Asked by At

I am using DarkaOnLine/L5-Swagger package for project. Here is example annotation

/**
 * @OA\Post(
 * //annotations etc..
 *     )
 */
public function login(LoginRequest $request): JsonResponse
{
    //login method
}

But using annotations in controllers complicates the code. Is there another way to do it in separate file?

1

There are 1 answers

0
DerManoMann On

Not sure it complicates things - with separate files you always have to update two different places.

Your annotations can be whereever you like as long as they are associated with structural elements (class, method, etc) so reflection can find them (means you need to create dummy classes, etc if the annotations are separate from the "real" code).

Also, those files need to be found by the bundle but I would expect you can configure multiple path to scan.

The downside for me is that you need to replicate all details, in particular type-hints and keep them in sync.