Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 1ed18c6

Browse files
authored
Update README.md
1 parent fb44a22 commit 1ed18c6

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ Base on [Gii, the Yii Framework Code Generator](https://www.yiiframework.com/ext
1010
[![License](https://poser.pugx.org/cebe/yii2-openapi/license)](https://packagist.org/packages/cebe/yii2-openapi)
1111
![yii2-openapi](https://github.com/cebe/yii2-openapi/workflows/yii2-openapi/badge.svg?branch=wip)
1212

13-
## what should this do?
13+
## TLDR; what is this?
14+
15+
A code generator for OpenAPI and Yii Framework based PHP API application.
1416

1517
Input: [OpenAPI 3.0 YAML or JSON](https://github.com/OAI/OpenAPI-Specification#the-openapi-specification) (via [cebe/php-openapi](https://github.com/cebe/php-openapi))
1618

17-
Output: Controllers, Models, database schema
19+
Output: Yii Framework Application with Controllers, Models, database schema
20+
1821

1922
## Features
2023

21-
This library is currently work in progress, current features are checked here when ready:
24+
Currently available features:
2225

23-
- [x] generate Controllers + Actions
24-
- [x] generate Models
25-
- [x] generate Database migration
26-
- [x] provide Dummy API via Faker
27-
- [x] update Database and models when API schema changes
26+
- Generate Path mappings, **Controllers** and Actions **for API Endpoints**. CRUD Endpoints are ready-to-use, other Endpoints are generated as abstract functions that need to be implemented
27+
- Generate **Models** and validation based on OpenAPI Schema
28+
- Generate **Database Schema** from OpenAPI Schema
29+
- Generates **Database Migrations** for schema changes
30+
- Provide **Dummy Data** via Faker for development
2831

2932
## Requirements
3033

@@ -33,7 +36,7 @@ This library is currently work in progress, current features are checked here wh
3336

3437
## Install
3538

36-
composer require cebe/yii2-openapi:^2.0@alpha
39+
composer require cebe/yii2-openapi:^2.0@beta
3740

3841
## Usage
3942

@@ -116,8 +119,8 @@ Explicitly specify primary key name for table, if it is different from "id"
116119

117120
### `x-db-type`
118121

119-
Explicitly specify the database type for a column. (MUST contains only real DB type! (`json`, `jsonb`, `uuid`, `varchar` etc.)).
120-
If x-db-type sets as `false`, property will be processed as virtual;
122+
Explicitly specify the database type for a column. (MUST contain only real DB type! (`json`, `jsonb`, `uuid`, `varchar` etc.)).
123+
If `x-db-type` is set to `false`, property will be processed as virtual;
121124
It will be added in model as public property, but skipped for migrations generation.
122125

123126
Example values of `x-db-type` are:
@@ -139,6 +142,7 @@ Such values are not allowed:
139142
- MEDIUMINT(10) UNSIGNED ZEROFILL NULL DEFAULT '7' COMMENT 'comment' AFTER `seti`, ADD INDEX `t` (`w`)
140143

141144
### `x-indexes`
145+
142146
Specify table indexes
143147

144148
```yaml
@@ -241,7 +245,18 @@ User:
241245
- see both examples here [tests/specs/many2many.yaml](tests/specs/many2many.yaml)
242246
243247
244-
## Things to keep in mind
248+
## Assumptions
249+
250+
When generating code from an OpenAPI description there are many possible ways to achive a fitting result.
251+
Thus there are some assumptions and limitations that are currently applied to make this work.
252+
Here is a (possibly incomplete) list:
253+
254+
- The current implementation works best with OpenAPI description that follows the [JSON:API](https://jsonapi.org/) guidelines.
255+
- The request and response format/schema is currently not extracted from OpenAPI schema and may need to be adjusted manually if it does not follow JSON:API
256+
- column/field/property with name `id` is considered as Primary Key by this library and it is automatically handled by DB/Yii; so remove it from validation `rules()`
257+
- other fields can currently be used as primary keys using the `x-pk` OpenAPI extension (see below) but it may not be work correctly in all cases, please report bugs if you find them.
258+
259+
Other things to keep in mind:
245260
246261
### Adding columns to existing tables
247262
@@ -256,7 +271,7 @@ Such a migration will fail when the table is not empty:
256271
$this->addColumn('{{%company}}', 'name', $this->string(128)->notNull());
257272
```
258273

259-
Fail on a PostgreSQL database with
274+
Fails on a PostgreSQL database with
260275

261276
> add column name string(128) NOT NULL to table {{%company}} ...Exception: SQLSTATE[23502]: Not null violation: 7 ERROR: column "name" contains null values
262277
@@ -330,6 +345,7 @@ It work on MariaDb.
330345
```
331346

332347
### Handling of `numeric` (#numeric, #MariaDb)
348+
333349
precision-default = 10
334350
scale-default = 2
335351

@@ -360,6 +376,7 @@ DB-Result = decimal(12,2)
360376
```
361377
DB-Result = decimal(10,2)
362378

379+
363380
## Screenshots
364381

365382
Gii Generator Form:
@@ -370,6 +387,7 @@ Generated files:
370387

371388
![Gii Generated Files](doc/screenshot-files.png)
372389

390+
373391
# Development
374392

375393
There commands are available to develop and check the tests. It can be used inside the Docker container. To enter into bash of container run `make cli` .
@@ -396,6 +414,7 @@ To apply multiple migration with one command:
396414
./yii migrate-pgsql/down --interactive=0 4
397415
```
398416

417+
399418
# Support
400419

401420
**Need help with your API project?**

0 commit comments

Comments
 (0)