Generate full REST API application from OpenAPI 3 specification.

1.0.2 2019-06-26 12:55 UTC

This package is auto-updated.

Last update: 2020-08-04 12:20:03 UTC


REST API application generator for Yii2, openapi 3.0 YAML -> Yii2.

Base on Gii, the Yii Framework Code Generator.

Latest Stable Version Total Downloads License Build Status

what should this do?

Input: OpenAPI 3.0 YAML or JSON (via cebe/php-openapi)

Output: Controllers, Models, database schema


This library is currently work in progress, current features are checked here when ready:

  • generate Controllers + Actions

  • generate Models

  • generate Database migration

  • provide Dummy API via Faker

  • update Database and models when API schema changes


  • PHP 7.1 or higher


composer require cebe/yii2-openapi:@beta cebe/php-openapi:@beta


You can use this package in your existing application or start a new project using the yii2-app-api application template. For usage of the template, see instructions in the template repo readme.

In your existing Yii application config (works for console as well as web):

$config = [
    // ... this is your application config ...

if (YII_ENV_DEV) {
    // enable Gii module
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => yii\gii\Module::class,
        'generators' => [
            // add ApiGenerator to Gii module
            'api' => \cebe\yii2openapi\generator\ApiGenerator::class,

return $config;

To use the web generator, open index.php?r=gii and select the REST API Generator.

On console you can run the generator with ./yii gii/api --openApiPath=@app/openapi.yaml. Where @app/openapi.yaml should be the absolute path to your OpenAPI spec file. This can be JSON as well as YAML (see also cebe/php-openapi for supported formats).

Run ./yii gii/api --help for all options.

OpenAPI extensions

This library understands the following extensions to the OpenAPI spec:


You may specify custom PHP code for generating fake data for a property:

          type: integer
          type: array
            type: string
          example: ['one', 'two']
          x-faker: "$faker->randomElements(['one', 'two', 'three', 'four'])"


Gii Generator Form:

Gii Generator Form

Generated files:

Gii Generated Files


Need help with your API project?

Professional support, consulting as well as software development services are available:

Development of this library is sponsored by cebe.☁️ "Your Professional Deployment Platform".