2017 © Pedro Peláez
 

yii2-extension yii2-rest-doc

A Yii2 tool to create slate index.md for you REST controllers.

image

pahanini/yii2-rest-doc

A Yii2 tool to create slate index.md for you REST controllers.

  • Saturday, February 3, 2018
  • by pahanini
  • Repository
  • 8 Watchers
  • 33 Stars
  • 9,180 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 19 Forks
  • 6 Open issues
  • 12 Versions
  • 5 % Grown

The README.md

Yii2 Rest Controller Documentator

Build Status StyleCI Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

About

Create precise documentation to your Yii2 API REST controllers. Library parses your code and generates objects with meta data that could be used with any template engine to generate great API docs., (*2)

You do not need to edit documentation when you change you code. Just rebuild you docs with this tool., (*3)

Install

  • Add "pahanini/yii2-rest-doc": "*" to required section of your composer.json
  • Add to your console application config

``` php, (*4)

'controllerMap' => [ 'build-rest-doc' => [ 'sourceDirs' => [ '@frontend\controllers\rest', // '//restdoc/restdoc.twig', 'class' => '\pahanini\restdoc\controllers\BuildController', 'sortProperty' => 'shortDescription', // 'path/to/nice-documentation.html' ], ], (*5)


## Template example (twig) ``` html {% for controller in controllers %} <h2>{{ controller.shortDescription }}</h2> <p>{{ controller.longDescription }}</p> {% if controller.hasLabel('authenticated') %} <div class="warning">Require login and password!</div> {% endif %} <p>List of supported actions: <ul> {% for action in controller.actions %} <li>{{ action }}</li> {% endfor %} </ul> </p> <p>Get params available for index action:</p> <ul> {% for item in controller.query %} <li> <b>{{ item.variableName }}</b> - {{ item.description }}, default - {{ item.defaultValue }} </li> {% endfor %} </ul> </p> <p>Model fields:</p> <table> <tr> <th>Name</th> <th>Type</th> <th>Description</th> <th>Can be updated?</th> </tr> {% for item in controller.model.fields %} <tr> <td>{{ item.name }}</td> <td>{{ item.type }}</td> <td>{{ item.description }}</td> <td>{{ item.isInScenario('api-update') ? 'yes' : 'no' }}</td> </tr> {% endfor %} </table> {% endfor %}

Data available in template

List of data automatically extracted from code:, (*6)

  • controller name
  • action's of each controller
  • model fields
  • extra fields
  • model rules (TBD)

List of special tags:, (*7)

  • short and long description of controller
  • query tags

Inheritance is also supported. Use @inherited or @inheritdoc tags., (*8)

Controller

  • @restdoc-ignore - skip controller.
  • @restdoc-label name - mark controller with label. Label name available via controller.hasLabel('labelName') in template
  • @restdoc-query name=false Name of part of name to find users - query params with description.

Model

To describe model's fields you can use two approaches., (*9)

If you already have phpDocumentator @property tag you can use it to describe API field. Model's doc block example:, (*10)


/** * My model. * * @property string $title Model's title */
  • @restdoc-link $title - use $title property to describe $title api field
  • @restdoc-link title $model_title - use $title property to describe $model_title api field

Separate field description

If you do not have @property tag or API field is not directly connected with property use @restdoc-field tag., (*11)

Example:, (*12)


/** * @restdoc-field int $id ID * @restdoc-field string $title Model's title */

Extra fields

Use @restdoc-extraField and @restdoc-extraLink for extra fields., (*13)

Sort fields

Use @restdoc-sortField to sort field according to your code., (*14)

Skip fields

Use @restdoc-ignore to skip field., (*15)


/** * @restdoc-ignore $hidden */

Integrate With Slate

Slate is probably one of the best tools to generate nice API. So you can use this tool to create index.md file for slate. You can use on afterAction event to automatically start slate., (*16)

Example:, (*17)

php 'controllerMap' => [ 'build-rest-doc' => [ 'sourceDirs' => [ '@frontend\controllers\rest', ], 'template' => '//restdoc/restdoc.twig', 'class' => '\pahanini\restdoc\controllers\BuildController', 'targetFile' => 'path/to/slate/index.md', 'on afterAction' => function() { exec("bundle exec middleman build") } ], ], (*18)

Rationale

Creating of Yii2 controllers is an easy task, but supporting of documentation in actual state is often boring and tough challenge. Using automatic tool like phpDocumentator or swagger makes life easier but its still require to describe all models fields and rules using tags or comments., (*19)

In other hand Yii2 controllers and models keep a lot of information about internal structure like actions,
field names, scenarios for update and insert operations. This package extracts such an information from REST controllers and models and using this data along with phpdocumentator tags automatically generates index.md for slate or any other documentation file., (*20)

The Versions

03/02 2018

dev-master

9999999-dev https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

22/03 2017

0.0.10

0.0.10.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

11/03 2017

dev-analysis-zOPEwa

dev-analysis-zOPEwa https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

08/03 2017

0.0.9

0.0.9.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

10/05 2016

0.0.8

0.0.8.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

25/08 2015

0.0.7

0.0.7.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

24/08 2015

0.0.6

0.0.6.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

30/07 2015

0.0.5

0.0.5.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

30/07 2015

0.0.4

0.0.4.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

30/07 2015

0.0.3

0.0.3.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

19/05 2015

0.0.2

0.0.2.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate

22/04 2015

0.0.1

0.0.1.0 https://github.com/pahanini/yii2-rest-to-slate

A Yii2 tool to create slate index.md for you REST controllers.

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavel Tetyaev

api rest yii2 doc slate