How to prefix all the URLs of a swagger with L5-Swagger?

42 Views Asked by At

I am using L5-Swagger to build my swagger in PHP with Laravel. Can we prefix all endpoint URLs so as not to repeat them for each one? Typically the prefix "/api/v1" in this example:

enter image description here

I saw several options in config.l5-swagger.php, but I tried many things and failed to do so.

1

There are 1 best solutions below

1
Mohsen On BEST ANSWER

add this on top of your controller:

/**
 *
 * @OA\Info(
 *     version="1.0.0",
 *     title="Organization",
 *     description="test description",
 *     @OA\Contact(
 *         name="test",
 *         email="test@test"
 *     ),
 * ),
 * @OA\Server(
 *     url="/api/v1",
 * ),
 */
class YourController extends Controller

then you have to set like this documentation for all of your controller method.

suggestion: if you using PHP 8.1 or higher Laravel 8.x or higher instead of using L5-Swagger use dedoc/scramble it will generate document automatically for you and it's build on top of swagger

https://scramble.dedoc.co