Giter VIP home page Giter VIP logo

php-apidoc's Introduction

php-apidoc

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

Requirements

PHP >= 5.3.2

Installation

The recommended installation is via compososer. Just add the following line to your composer.json:

{
    ...
    "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:

# 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

$ php apidoc.php

Available Methods

Here is the list of methods available so far :

  • @ApiDescription(section="...", description="...")
  • @ApiMethod(type="(get|post|put|delete")
  • @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/

Tips

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

* @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 !

TODO

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

php-apidoc's People

Contributors

calinrada avatar kbsali avatar gnuget avatar lahaxearnaud avatar pvullioud avatar nataliaaznar avatar cameron-fgx avatar ruifil avatar jabiinfante avatar mchurichi avatar

Stargazers

 avatar

Watchers

Jon Latorre avatar Kaian avatar James Cloos avatar Asier avatar Mikel Eizagirre avatar Koldo Picaza avatar Gorka Rodrigo avatar Aique avatar Lander Ontoria Gardeazabal avatar  avatar Iñigo Lacoume avatar  avatar Ander Mendiola avatar Luis Felipe García Fernández avatar  avatar  avatar Victor Vargas avatar Digitalis avatar German avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.