nostop8 / yii2-rest-api-doc

Simple documentation generator for Yii2 REST applications based on defined API endpoints and actions annotations.
MIT License
21 stars 15 forks source link

yii2-rest-api-doc

Simple documentation generator for Yii2 REST applications based on defined API endpoints and actions annotations.

Installation

Alternatively add into require section of your composer.json following string "nostop8/rest-api-doc": "*" and run composer update

Usage

  1. Rest Description: Your endpoint description.
  2. Rest Fields: ['field1', 'field2'] or ['field3', 'field4']. (Please, note: or and array after it is extra and might be skipped if your service accepts only one type of body)
  3. Rest Filters: ['filter1', 'filter2'].
  4. Rest Expand: ['expandRelation1', 'expandRelation2'].

Example of annotations

<?php

namespace app\controllers;

class ExampleController extends \yii\rest\ActiveController
{

    /**
     * Rest Description: Your endpoint description.
     * Rest Fields: ['field1', 'field2'].
     * Rest Filters: ['filter1', 'filter2'].
     * Rest Expand: ['expandRelation1', 'expandRelation2'].
     */
    public function actionTest()
    {
        return ['field1', 'field2'];
    }
}

As you may see from this example, every annotation starts with its name and collon (:) and ends with a dot (.). Also the body of every annotation type might consist of PHP array. You must follow this rules in order to define properly documentation description and service testing functionality.

Extra Tip

While developing API which should be depended on 3-rd party that are not available yet for some reason, it might be useful for you to use an external online API mocking tool - QuickMocker. It is also useful while integrating your application with webhooks to debug requests that arrive from some 3-rd party while you do not host your application remotely.