RESTful API Doc using SLIM and SWAGGER?

user2942586 picture user2942586 · Apr 30, 2014 · Viewed 18.6k times · Source

I am new to this stuff but I love it. I made a little REST Api using the Slim Framework. Now I would like to have an ongoing documentation about it. I think swagger is the right choice but I have not found out yet how to integrate it ?

Cheers & thanks for your patience :)

Answer

adosaiguas picture adosaiguas · Apr 30, 2014

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.