Yii Framework Forum: Swagger-php on Yii2 ActiveController - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Swagger-php on Yii2 ActiveController

#1 User is offline   valmor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 23-May 17

Posted 23 May 2017 - 03:05 PM

I also posted my question on STackOverflow (44032555) but without success so trying it on this forum:


I have a REST api running in my yii2 app. I extend my api model from my AR model and use the fields() function to define the api response fields.

 * @SWG\Definition(
 *   type="object"
 * )
class Person extends \common\models\Person implements Linkable {

    public function fields() {
        return ['id',
                'first-name' => 'first_name'

    public function getLinks() {
        return [
                Link::REL_SELF  => Url::to(['person/view', 'id' => $this->id], true),

My activecontroller is the easiest implementation

use yii\rest\ActiveController;
 * @SWG\Info(title="My First API", version="0.1")
class PersonController extends ActiveController {

    public $modelClass = 'api\modules\v1\models\Person';


So far, everything works. Then I wanted to add Swagger-php to document my API: I use light/yii2-swagger. The configuration works and I have my swagger-ui page/json.

The next step is to start adding documentation... But in all the Swagger-php examples or on github.com/lichunqiang/yii2-swagger-demo, the annotations are on the modelfields and the controller methods. The problem is that those are not explicitly in the code because of ActiveRecord and the fields() function.

Is there are way to combine swagger-php and ActiveController?

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users