Xavier W.
Xavier W.

Reputation: 1360

Generating REST documentation in a Codeigniter project

I have a REST webservice using Codeigniter and using this lib : https://github.com/chriskacerguis/codeigniter-restserver

I want to generate documentation for this web service. I look to use Swagger UI to generate this documentation. But, I didn't find any documentation how to use Swagger with Codeigniter.

The only project using this two technologies is this one, but don't have a good documentation : https://github.com/panxp/codeigniter-swagger

Can someone paste an example using this two technologies or give me a link to a good documentation ? Of course, if there is another good lib to generate documentation, I'll take it if it's usable with Codeigniter.

Upvotes: 10

Views: 13674

Answers (3)

Sunchock
Sunchock

Reputation: 378

The recommended way to automate API documentation is to generate an OpenAPI specification file from your source code that can be used by other tools such as editors, viewers, live testing, etc.

The OpenAPI specification file can be either in Yaml or JSON format and the definition reference can be found in this github repository here : OpenAPI Specification v3.1.1

For CodeIgniter (PHP), you can use swagger-php which is a composer package capable of generating the OpenAPI spec file from attributes or annotations in your PHP source code.


From Swagger-PHP website :

1. Install with composer:

composer require zircote/swagger-php

2. Update your code

<?php

use OpenApi\Annotations as OA;

/**
 * @OA\Info(
 *     title="My First API",
 *     version="0.1"
 * )
 */
class OpenApi
{
}

class MyController
{

    /**
     * @OA\Get(
     *     path="/api/data.json",
     *     @OA\Response(
     *         response="200",
     *         description="The data"
     *     )
     * )
     */
    public function getResource()
    {
        // ...
    }
}

3. Generate OpenAPI documentation

./vendor/bin/openapi src -o openapi.yaml

4. Explore and interact with your API

Use an OpenAPI tool like Swagger UI to explore and interact with your API.

Upvotes: 0

Vibhor Sharma
Vibhor Sharma

Reputation: 1

You Can use https://github.com/manish29ify/codeigniter3-restapi-with-swagger Still it is under development but you can use Swagger with PHP rest server very easily

Upvotes: 0

caseyh
caseyh

Reputation: 448

In past projects I have used http://apidocjs.com/ which I find pretty easy to use and straightforward to generate from in multiple environments. It took me like 15-20 minutes to get going and looking how I wanted with it having npm already installed. This one doesn't really care about directory or code structure, just your supplied info in the doc blocks.

Upvotes: 8

Related Questions