yii2-openapi

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

Github星跟蹤圖

yii2-openapi

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

Features

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

Requirements

  • PHP 7.1 or higher

Install

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

Usage

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):

<?php
$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:

x-faker

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

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

Screenshots

Gii Generator Form:

Gii Generator Form

Generated files:

Gii Generated Files

Support

Need help with your API project?

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

https://www.cebe.cc/en/contact

Development of this library is sponsored by cebe.:cloud: "Your Professional Deployment Platform".

主要指標

概覽
名稱與所有者cebe/yii2-openapi
主編程語言PHP
編程語言PHP (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2018-10-23 10:39:18
推送於2024-06-04 15:27:09
最后一次提交2024-06-04 17:27:09
發布數7
最新版本名稱2.0-beta2 (發布於 )
第一版名稱0.9.0-beta (發布於 )
用户参与
星數128
關注者數9
派生數22
提交數760
已啟用問題?
問題數99
打開的問題數24
拉請求數74
打開的拉請求數0
關閉的拉請求數7
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?