Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful API Doc using SLIM and SWAGGER?

Tags:

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 :)

like image 771
user2942586 Avatar asked Apr 30 '14 19:04

user2942586


People also ask

How do I write an API document with Swagger?

Head over to Swagger Inspector, and insert the end point of the resource you want to have documented. You can then navigate to the right panel from the History section of Swagger Inspector, and click "Create API definition" to create the OAS definition.

Is REST API documentation template available on Swagger?

Note that Swagger not only helps us to design and document REST APIs, it also lets us build (Server Stub) and Consume (Rest Clients) REST APIs. The major Swagger tools include: Swagger Editor — browser-based editor where one can write OpenAPI specification.

Is Swagger API RESTful?

Swagger™ is a project used to describe and document RESTful APIs. The Swagger specification defines a set of files required to describe such an API.


1 Answers

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.

like image 174
adosaiguas Avatar answered Sep 19 '22 19:09

adosaiguas