All Projects → pahanini → yii2-rest-doc

pahanini / yii2-rest-doc

Licence: other
Yii2 REST doc generator

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-rest-doc

Yii2 Migration
Yii 2 Migration Creator And Updater
Stars: ✭ 262 (+648.57%)
Mutual labels:  yii2, generator
Yii2 Enhanced Gii
Enhanced Yii2 Gii (generator) that generates related Models & CRUD
Stars: ✭ 183 (+422.86%)
Mutual labels:  yii2, generator
Yii2 Apidoc
Yii 2 apidoc extension.
Stars: ✭ 236 (+574.29%)
Mutual labels:  yii2, generator
yii2-merit
Reputation engine for Yii2 用于实现积分,等级功能的设计
Stars: ✭ 16 (-54.29%)
Mutual labels:  yii2
yii2-dynamic-fields
Widget for display dynamic fields, adding and removing their using Pjax.
Stars: ✭ 52 (+48.57%)
Mutual labels:  yii2
BFSG
BFSG - BruteForce String Generator 😾
Stars: ✭ 16 (-54.29%)
Mutual labels:  generator
Yii2-Youtube-Clone
Youtube clone made with Yii2 framework
Stars: ✭ 91 (+160%)
Mutual labels:  yii2
yii2-tinymce
Yii2 extension, tinymce wysiwyg editor
Stars: ✭ 16 (-54.29%)
Mutual labels:  yii2
yii2-star-rating
Star rating widget based on jQuery Raty
Stars: ✭ 16 (-54.29%)
Mutual labels:  yii2
styled-svg
A styled-components generator for SVG files to use in react
Stars: ✭ 37 (+5.71%)
Mutual labels:  generator
awesome-yii2
Curated list of resources about using Yii2 - Yii is a high-performance component-based PHP framework.
Stars: ✭ 36 (+2.86%)
Mutual labels:  yii2
illuminate
Yii2 to Laravel Migration Package
Stars: ✭ 71 (+102.86%)
Mutual labels:  yii2
python-lorem
🐍 Python library for the generation of random text that looks like Latin
Stars: ✭ 19 (-45.71%)
Mutual labels:  generator
api
CashWarden API
Stars: ✭ 34 (-2.86%)
Mutual labels:  yii2
roadifier
Open Source road mesh generator script for Unity
Stars: ✭ 30 (-14.29%)
Mutual labels:  generator
filedb
ActiveRecord for static data definitions based on files
Stars: ✭ 72 (+105.71%)
Mutual labels:  yii2
liferay-starter
Generate & download your Liferay workspace from a webapp.
Stars: ✭ 25 (-28.57%)
Mutual labels:  generator
yii2-db
Database extensions for Yii 2.0 Framework 📦
Stars: ✭ 19 (-45.71%)
Mutual labels:  yii2
yii2-telegram
Support chat for site based on Telegram bot
Stars: ✭ 49 (+40%)
Mutual labels:  yii2
reactcci
React create component interactive CLI
Stars: ✭ 49 (+40%)
Mutual labels:  generator

Yii2 Rest Controller Documentator

Build Status StyleCI Latest Stable Version Total Downloads Latest Unstable Version License

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.

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

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',   // <-- path to your API controllers
		],
		'template' => '//restdoc/restdoc.twig', 
		'class' => '\pahanini\restdoc\controllers\BuildController',
		'sortProperty' => 'shortDescription', // <-- default value (how controllers will be sorted)
		'targetFile' => 'path/to/nice-documentation.html'
	],
]

Template example (twig)

{% 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:

  • 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

  • @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.

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

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

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

Sort fields

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

Skip fields

Use @restdoc-ignore to skip field.

/**
 * @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.

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

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.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].