PHPackages                             pahanini/yii2-rest-doc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. pahanini/yii2-rest-doc

ActiveYii2-extension[HTTP &amp; Networking](/categories/http)

pahanini/yii2-rest-doc
======================

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

0.0.12(6y ago)3628.3k↑12.5%19[8 issues](https://github.com/pahanini/yii2-rest-doc/issues)[2 PRs](https://github.com/pahanini/yii2-rest-doc/pulls)BSD-3-ClausePHPPHP &gt;=7.1.0

Since Apr 22Pushed 5y ago6 watchersCompare

[ Source](https://github.com/pahanini/yii2-rest-doc)[ Packagist](https://packagist.org/packages/pahanini/yii2-rest-doc)[ Docs](https://github.com/pahanini/yii2-rest-to-slate)[ RSS](/packages/pahanini-yii2-rest-doc/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (16)Used By (0)

Yii2 Rest Controller Documentator
=================================

[](#yii2-rest-controller-documentator)

[![Build Status](https://camo.githubusercontent.com/70fed7d228854381c6e8398028584f9b43c80b33d72c705db1b7e11ae034fa67/68747470733a2f2f7472617669732d63692e6f72672f706168616e696e692f796969322d726573742d646f632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pahanini/yii2-rest-doc)[![StyleCI](https://camo.githubusercontent.com/cefed886b4ed3727bf6394021ab07f5d9a81c31768680e425312b71cc8e6ec13/68747470733a2f2f7374796c6563692e696f2f7265706f732f33333731313734392f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/33711749)[![Latest Stable Version](https://camo.githubusercontent.com/e8f9e6760df9edcfee1e9c7fdf6848f4ff8220d6e5ea7299a75ad0bd2238d845/68747470733a2f2f706f7365722e707567782e6f72672f706168616e696e692f796969322d726573742d646f632f762f737461626c65)](https://packagist.org/packages/pahanini/yii2-rest-doc)[![Total Downloads](https://camo.githubusercontent.com/22a6e1ecda2972f4c71b2c3e07a500d05dbbfb3fb00c3681514057f39debeadb/68747470733a2f2f706f7365722e707567782e6f72672f706168616e696e692f796969322d726573742d646f632f646f776e6c6f616473)](https://packagist.org/packages/pahanini/yii2-rest-doc)[![Latest Unstable Version](https://camo.githubusercontent.com/0d7c68943d9714959069c3aed27b750655f159eed1ab7c39c64f3bc6aacb01a1/68747470733a2f2f706f7365722e707567782e6f72672f706168616e696e692f796969322d726573742d646f632f762f756e737461626c65)](https://packagist.org/packages/pahanini/yii2-rest-doc)[![License](https://camo.githubusercontent.com/7ad7cf6ce1cbb783c337133e9458d4feabc14fd54277d4c93ff69bf41b64ca3d/68747470733a2f2f706f7365722e707567782e6f72672f706168616e696e692f796969322d726573742d646f632f6c6963656e7365)](https://packagist.org/packages/pahanini/yii2-rest-doc)

About
-----

[](#about)

Create precise documentation to your Yii2 API [REST](http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html)controllers. Library parses your code and generates objects with meta data that could be used with any template engine to generate great API docs.

You do not need to edit documentation when you change you code. Just rebuild you docs with this tool.

Install
-------

[](#install)

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

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

Template example (twig)
-----------------------

[](#template-example-twig)

```
{% for controller in controllers %}
	{{ controller.shortDescription }}
	{{ controller.longDescription }}
	{% if controller.hasLabel('authenticated') %}
		Require login and password!
	{% endif %}
	List of supported actions:

			{% for action in controller.actions %}
				{{ action }}
			{% endfor %}

	Get params available for index action:

			{% for item in controller.query %}

					{{ item.variableName }} - {{ item.description }}, default - {{ item.defaultValue }}

			{% endfor %}

	Model fields:

			Name
			Type
			Description
			Can be updated?

		{% for item in controller.model.fields %}

				{{ item.name }}
				{{ item.type }}
				{{ item.description }}
				{{ item.isInScenario('api-update')  ? 'yes' : 'no' }}

		{% endfor %}

{% endfor %}
```

Data available in template
--------------------------

[](#data-available-in-template)

List of data automatically extracted from code:

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

List of special tags:

- short and long description of controller
- query tags

Inheritance is also supported. Use `@inherited` or `@inheritdoc` tags.

### Controller

[](#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

[](#model)

To describe model's fields you can use two approaches.

#### Link to property tag.

[](#link-to-property-tag)

If you already have phpDocumentator `@property` tag you can use it to describe API field. Model's doc block example:

```
/**
 * 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

[](#separate-field-description)

If you do not have `@property` tag or API field is not directly connected with property use `@restdoc-field` tag.

Example:

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

### Extra fields

[](#extra-fields)

Use @restdoc-extraField and @restdoc-extraLink for extra fields.

### Sort fields

[](#sort-fields)

Use @restdoc-sortField to sort field according to your code.

### Skip fields

[](#skip-fields)

Use @restdoc-ignore to skip field.

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

Integrate With Slate
--------------------

[](#integrate-with-slate)

[Slate](https://github.com/tripit/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.

Example:

```
'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") }
	],
]
```

Rationale
---------

[](#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](https://github.com/phpDocumentor/phpDocumentor2)or [swagger](http://swagger.io/) makes life easier but its still require to describe all models fields and rules using tags or comments.

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](https://github.com/tripit/slate) or any other documentation file.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~169 days

Recently: every ~370 days

Total

12

Last Release

2226d ago

PHP version history (2 changes)0.0.1PHP &gt;=5.4.0

0.0.11PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2ff5824ce711862778444b44442b7ae3b4aa7f1804a29da2c5ad375aecb5448?d=identicon)[pahanini](/maintainers/pahanini)

---

Top Contributors

[![pahanini](https://avatars.githubusercontent.com/u/898663?v=4)](https://github.com/pahanini "pahanini (77 commits)")[![PaVeL-Ekt](https://avatars.githubusercontent.com/u/2797861?v=4)](https://github.com/PaVeL-Ekt "PaVeL-Ekt (4 commits)")[![michkarevev](https://avatars.githubusercontent.com/u/37874234?v=4)](https://github.com/michkarevev "michkarevev (2 commits)")[![csminb](https://avatars.githubusercontent.com/u/6680882?v=4)](https://github.com/csminb "csminb (1 commits)")[![pastuhov](https://avatars.githubusercontent.com/u/7937221?v=4)](https://github.com/pastuhov "pastuhov (1 commits)")

---

Tags

documentationgeneratorrest-apislateyii2apirestdocyii2slate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pahanini-yii2-rest-doc/health.svg)

```
[![Health](https://phpackages.com/badges/pahanini-yii2-rest-doc/health.svg)](https://phpackages.com/packages/pahanini-yii2-rest-doc)
```

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.4k67.4M263](/packages/nelmio-api-doc-bundle)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[tuyakhov/yii2-json-api

Implementation of JSON API specification for the Yii framework

140119.0k](/packages/tuyakhov-yii2-json-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
