RESTful API Doc using SLIM and SWAGGER?

I think you are looking for this project: zircote/swagger-php

Here you'll find how to generate the doc on user request to a URL.

Basically you have to annotate your code with the Swagger Annotations, then create another route in Slim with a code similar to this:

<?php
use Swagger\Swagger;
$swagger = new Swagger('/project/root/top_level');
header("Content-Type: application/json")
echo $swagger->getResource('/pet', array('output' => 'json'));

And it will generate the Swagger API docs on the fly for you.


A short update to the answer of adosaiguas:

When using Slim Framework 4.0 and zircote/swagger-php one can provide an api endpoint providing the swagger / OpenAPI 3.0 json description using the following code:

use function OpenApi\scan;

 /**
 * @OA\Get(
 *     path="/openapi",
 *     tags={"documentation"},
 *     summary="OpenAPI JSON File that describes the API",
 *     @OA\Response(response="200", description="OpenAPI Description File"),
 * )
 */
$app->get('/openapi', function ($request, $response, $args) {
    $swagger = scan('--PATH TO PROJECT ROOT--');
    $response->getBody()->write(json_encode($swagger));
    return $response->withHeader('Content-Type', 'application/json');
});