2017 © Pedro Peláez
 

library php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

image

crada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  • Friday, March 9, 2018
  • by calin.rada
  • Repository
  • 23 Watchers
  • 215 Stars
  • 48,785 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 67 Forks
  • 3 Open issues
  • 11 Versions
  • 14 % Grown

The README.md

php-apidoc

Generate documentation for php API based application. No dependency. No framework required., (*1)

Requirements

PHP >= 5.3.2, (*2)

Installation

The recommended installation is via composer. Just add the following line to your composer.json:, (*3)

{
    ...
    "require": {
        ...
        "crada/php-apidoc": "@dev"
    }
}
$ php composer.phar update

Usage

<?php

namespace Some\Namespace;

class User
{
    /**
     * @ApiDescription(section="User", description="Get information about user")
     * @ApiMethod(type="get")
     * @ApiRoute(name="/user/get/{id}")
     * @ApiParams(name="id", type="integer", nullable=false, description="User id")
     * @ApiParams(name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}")
     * @ApiReturnHeaders(sample="HTTP 200 OK")
     * @ApiReturn(type="object", sample="{
     *  'transaction_id':'int',
     *  'transaction_status':'string'
     * }")
     */
    public function get()
    {

    }

    /**
     * @ApiDescription(section="User", description="Create's a new user")
     * @ApiMethod(type="post")
     * @ApiRoute(name="/user/create")
     * @ApiParams(name="username", type="string", nullable=false, description="Username")
     * @ApiParams(name="email", type="string", nullable=false, description="Email")
     * @ApiParams(name="password", type="string", nullable=false, description="Password")
     * @ApiParams(name="age", type="integer", nullable=true, description="Age")
     */
    public function create()
    {

    }
}

Create an apidoc.php file in your project root folder as follow:, (*4)

# apidoc.php
<?php

use Crada\Apidoc\Builder;
use Crada\Apidoc\Exception;

$classes = array(
    'Some\Namespace\User',
    'Some\Namespace\OtherClass',
);

$output_dir  = __DIR__.'/apidocs';
$output_file = 'api.html'; // defaults to index.html

try {
    $builder = new Builder($classes, $output_dir, 'Api Title', $output_file);
    $builder->generate();
} catch (Exception $e) {
    echo 'There was an error generating the documentation: ', $e->getMessage();
}

Then, execute it via CLI, (*5)

$ php apidoc.php

Available Methods

Here is the list of methods available so far :, (*6)

  • @ApiDescription(section="...", description="...")
  • @ApiMethod(type="(get|post|put|delete|patch")
  • @ApiRoute(name="...")
  • @ApiParams(name="...", type="...", nullable=..., description="...", [sample=".."])
  • @ApiHeaders(name="...", type="...", nullable=..., description="...")
  • @ApiReturnHeaders(sample="...")
  • @ApiReturn(type="...", sample="...")
  • @ApiBody(sample="...")

Preview

You can see a dummy generated documentation on http://calinrada.github.io/php-apidoc/, (*7)

Tips

To generate complex object sample input, use the ApiParam "type=(object|array(object)|array)":, (*8)

* @ApiParams(name="data", type="object", sample="{'user_id':'int','profile':{'email':'string','age':'integer'}}")

Known issues

I don't know any, but please tell me if you find something. PS: I have tested it only in Chrome !, (*9)

TODO

  • Implement options for JSONP
  • Implement "add fields" option

The Versions

09/03 2018

dev-master

9999999-dev https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada
by Borja Santos-Diez

api php generator documentation

09/03 2018

1.3.9

1.3.9.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada
by Borja Santos-Diez

api php generator documentation

09/03 2018

1.3.8

1.3.8.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada
by Borja Santos-Diez

api php generator documentation

19/02 2018

1.3.7

1.3.7.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada
by Borja Santos-Diez

api php generator documentation

19/02 2018

1.3.6

1.3.6.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada
by Borja Santos-Diez

api php generator documentation

03/02 2015

1.3.5

1.3.5.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada
by Borja Santos-Diez

api php generator documentation

13/06 2014

1.3.4

1.3.4.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada

api php generator documentation

09/12 2013

1.3.3

1.3.3.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada

api php generator documentation

26/11 2013

1.3.2

1.3.2.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada

api php generator documentation

26/11 2013

1.3.1

1.3.1.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada

api php generator documentation

22/11 2013

1.3.0

1.3.0.0 https://github.com/calinrada/php-apidoc

Generate documentation for php API based application. No dependency. No framework required.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

by Calin Rada

api php generator documentation