CodeIgniter Forums
Package for generating API Documentation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Package for generating API Documentation (/showthread.php?tid=90757)



Package for generating API Documentation - vimkaf - 04-29-2024

Hello Everyone,
I want to ask if there is a package to generate API documentation directly from code using docparams, annotations or attributes. A similar package would be https://scribe.knuckles.wtf/laravel for the laravel framework. It would be nice to do this in CI.
Thanks.


RE: Package for generating API Documentation - Bosborne - 04-29-2024

Php documentor or doxygen can generate code documentation. Many programs use Swagger to document and test their APIs.


RE: Package for generating API Documentation - vimkaf - 04-29-2024

(04-29-2024, 04:05 AM)Bosborne Wrote: Php documentor or doxygen can generate code documentation. Many programs use Swagger to document and test their APIs.

Thanks for your suggestion but PhpDocumentor and DOxygen are for code documentation and not API documentation. 

I am looking for something that will integrate well with my codeigniter application. 

For example: Imagine writing an API endpoint to check the status of services
PHP Code:
/**

* Healthcheck
*
* Check that the service is up. If everything is okay, you'll get a 200 OK response.
*
* Otherwise, the request will fail with a 400 error, and a response listing the failed services.
*
* @response 400 scenario="Service is unhealthy" {"status": "down", "services": {"database": "up", "redis": "down"}}
* @responseField status The status of this API (`up` or `down`).
* @responseField services Map of each downstream service and their status (`up` or `down`).
*/
$routes->get('healthcheck', function(){
     return response()->setJSON([
            'status' => 'up',
        'services' => [
            'database' => 'up',
            'redis' => 'up',
        ],
     ]);
}); 

Then I imagine running a CLI command like

Code:
php spark <packagename>:build


This command would generate static html files that can be published and would look something like this

[Image: docs-rich-1-5a0a10e597df07d31903d841aadb2df1.png]


I hope you are able to understand what I'm looking for.  Check  https://scribe.knuckles.wtf/laravel/documenting for more in-depth description.


RE: Package for generating API Documentation - Bosborne - 04-29-2024

I think Swagger can likely do what you want but nobody has integrated ir with Codeigniter 4. I see someone did some Codeigniter 3 integration many years ago.


RE: Package for generating API Documentation - vimkaf - 04-29-2024

(04-29-2024, 10:21 AM)Bosborne Wrote: I think Swagger can likely do what you want but nobody has integrated ir with Codeigniter 4. I see someone did some Codeigniter 3 integration many years ago.

Yes, Swagger can be used to achieve this but it is done separately and I have to describe the API schema and each path's request and response. It has no idea about my code. I am looking for something if possible generate the OpenAPI definitions as described in the Code that way when my code changes the API Doc Schema also changes.

Kindly send me a link to the CI3 integration you saw.


RE: Package for generating API Documentation - kenjis - 04-29-2024

How about this? https://github.com/zircote/swagger-php


RE: Package for generating API Documentation - vimkaf - 04-29-2024

(04-29-2024, 05:50 PM)kenjis Wrote: How about this? https://github.com/zircote/swagger-php

This will do. Thank you.