2017 © Pedro Peláez
 

library zf2-rest-api-documentator

Module generating REST API documentation

image

widmogrod/zf2-rest-api-documentator

Module generating REST API documentation

  • Tuesday, October 1, 2013
  • by widmogrod
  • Repository
  • 2 Watchers
  • 17 Stars
  • 7,035 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 19 Versions
  • 2 % Grown

The README.md

Module generating REST API documentation v1.6.1 Build Status

Introduction

This module allow to create quick documentation of your REST API., (*1)

Main features that I want to implement:, (*2)

  • Generate REST API documentation.
    • [√] Describe function of available parameters
    • [√] Create a general description of the parameters several times repeated
  • Unlimited number of documented APIs
    • [√] Create modules for ZF2 containing a good and standardized documentation
  • Elastic & simple to use.
    • [√] Use predefined interpreter for configuration or write it by your self
    • [-] Do you have a self-describing API and you want to automaticly build documentation from it? Help me, to write that kind of interpreter or wait until I'll do it
  • Well documented
    • [√] The module is shipped with API documentation, documented by this module.
    • [√] Some issues are described in tips & trick section
  • Posibility to test & play with API from docs page
    • [√] Execute API call from documentation
    • [-] Performing authorization (OAuth, BaseAuth, ...)

Read TODO.md for more information., (*3)

Installation

  1. cd my/project/directory
  2. Create a composer.json file with following content:

``` json { "require": { "widmogrod/zf2-rest-api-documentator": "1.*" } }, (*4)


3. Run `php composer.phar install` 4. Open ``my/project/folder/configs/application.config.php`` and: - add ``'WidRestApiDocumentator'`` to your ``'modules'`` parameter. - add ``'AsseticBundle'`` to your ``'modules'`` parameter (optional if you want to include CSS) ## Usage Bellow is php configuration file that show haw to implement simple REST API documentation in your module. This is a minimal configuration required to achieve result shown further dawn. ```php <?php return array( // Configuration namespace within this module looking for data 'zf2-rest-api-documentator' => array( // Contains collection of documentation descriptions. 'docs' => array( // Namespace of module within REST API description resides. Must be unique per module. 'my_module_name' => array( 'name' => 'api.example.com', 'version' => '1.1', 'baseUrl' => 'http://127.0.0.1:8080/api', // Strategy is way, in which this configuration will be interpreted. 'strategy' => 'standard', // General description for common thing in module, to skip redundancy 'general' => array( 'params' => array( 'id' => array( 'type' => 'integer', 'required' => true, 'description' => 'Resource identificator' ), 'limit' => array( 'type' => 'integer', 'description' => 'Limit API result to given value. Value must be between 1-100' ), 'order' => array( 'type' => 'string', 'required' => false, 'description' => 'Retrieve API result ordered by given value. Acceptable values: asc, desc.' ), ), ), // REST API Endpoints, here you're describing your API 'resources' => array( 'GET: /keywords' => 'Fetch list of keywords', 'POST: /keywords' => array( 'body' => array( 'type' => 'WidRestApiDocumentator\Body\JsonBody', 'params' => array( 'name' => array( 'type' => 'string', 'required' => true, 'description' => 'Keyword name', ), ), ), ), 'GET: /keywords/<id>' => 'Fetch specific keyword', 'GET: /keywords/<id>/search_engines?limit=&order=', 'GET: /keywords/<id>/domains_positions_in_search_engine', 'PUT: /users/me' => array( 'description' => 'Demonstration endpoint that use headers & body params', 'headers' => array( 'X-Login' => array( 'type' => 'string', 'required' => true, 'description' => 'Header is test header. Nothing special.' ), ), 'body' => array( 'params' => array( 'token' => array( 'type' => 'string', 'description' => 'Authorization token', ), ), ), ), ), ), ), ), );

Below is example showing how this configuration will look like., (*5)

To see this result, enter in browser your application addres and go to route /rest-api-docs., (*6)

Example API, (*7)

Tips & tricks

Setup you own route to your documentation.

``` php <?php return array( 'router' => array( 'routes' => array( 'rest-api-docs' => array( 'type' => 'Literal', 'options' => array( 'route' => '/my-api-doc', 'defaults' => array( 'controller' => 'WidRestApiDocumentator\Controller\Docs', 'action' => 'show', // NOTE: "my_module_name" is name of key in which your documentation was defined (see usage above) 'id' => 'my_module_name', // NOTE: This param, will disable back to list button. Is optional. Defaut value is "1". 'show_back_link' => 0, ))))));, (*8)


### Write your own strategy Currently module have one strategy named "standard". Strategy is way, in which documentation configuration will be interpreted. It's very useful way to create your own interpreter. To do that you need to do two things 1. Write your strategy implementing this interface `WidRestApiDocumentator\StrategyInterface` 2. Tell the module, that there is new strategy. Create this configuration entry: ``` php return array( 'zf2-rest-api-documentator' => array( 'strategies' => array( 'invokables' => array( 'myStrategy' => 'WidRestApiDocumentator\Strategy\Standard', ))));

How to run this module without installing ZendSkeletonApplication

  1. Clone this module git@github.com:widmogrod/zf2-rest-api-documentator.git
  2. Go to module directory
  3. run composer.phar install --dev
  4. create file index.php in module directory with content:

``` php <?php chdir(DIR); if (!is_dir('public/assets')) { mkdir('public/assets', 0777, true); }, (*9)

$config = array( 'modules' => array( 'AsseticBundle', 'WidRestApiDocumentator', ), 'module_listener_options' => array( 'config_glob_paths' => array( 'tests/config/autoload/{,*.}{global,local}.php', ), 'config_static_paths' => array( 'tests/config/autoload/assets.php', 'config/api.config.php', ), 'module_paths' => array( 'WidRestApiDocumentator' => DIR ), ), );, (*10)

require_once 'vendor/autoload.php';, (*11)

$app = Zend\Mvc\Application::init($config); $app->run(); ```, (*12)

  1. Run web server in this directory f.e. php -S 127.0.0.1:8080

Stability

Build Status on branch master, (*13)

Build Status on branch devel, (*14)

The Versions

01/10 2013

dev-master

9999999-dev

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

01/10 2013

1.6.3

1.6.3.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

02/08 2013

dev-devel

dev-devel

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

02/08 2013

1.6.2

1.6.2.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

04/05 2013

1.6.1

1.6.1.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

03/05 2013

1.6.0

1.6.0.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

29/04 2013

1.5.1

1.5.1.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2013

1.5.0

1.5.0.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

27/04 2013

1.4.1

1.4.1.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

27/04 2013

1.4.0

1.4.0.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

26/04 2013

1.3.1

1.3.1.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

26/04 2013

1.3.0

1.3.0.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

21/04 2013

1.2.2

1.2.2.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

20/04 2013

1.2.1

1.2.1.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

20/04 2013

1.2.0

1.2.0.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

15/04 2013

1.1.1

1.1.1.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

15/04 2013

1.1.0

1.1.0.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

15/04 2013

1.0.1

1.0.1.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires

14/04 2013

1.0.0

1.0.0.0

Module generating REST API documentation

  Sources   Download

MIT

The Requires

 

The Development Requires