You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 4, 2024. It is now read-only.
A code generator for OpenAPI and Yii Framework based PHP API application.
14
16
15
17
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))
16
18
17
-
Output: Controllers, Models, database schema
19
+
Output: Yii Framework Application with Controllers, Models, database schema
20
+
18
21
19
22
## Features
20
23
21
-
This library is currently work in progress, current features are checked here when ready:
24
+
Currently available features:
22
25
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
28
31
29
32
## Requirements
30
33
@@ -33,7 +36,7 @@ This library is currently work in progress, current features are checked here wh
33
36
34
37
## Install
35
38
36
-
composer require cebe/yii2-openapi:^2.0@alpha
39
+
composer require cebe/yii2-openapi:^2.0@beta
37
40
38
41
## Usage
39
42
@@ -116,8 +119,8 @@ Explicitly specify primary key name for table, if it is different from "id"
116
119
117
120
### `x-db-type`
118
121
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;
121
124
It will be added in model as public property, but skipped for migrations generation.
122
125
123
126
Example values of `x-db-type` are:
@@ -139,6 +142,7 @@ Such values are not allowed:
139
142
- MEDIUMINT(10) UNSIGNED ZEROFILL NULL DEFAULT '7' COMMENT 'comment' AFTER `seti`, ADD INDEX `t` (`w`)
140
143
141
144
### `x-indexes`
145
+
142
146
Specify table indexes
143
147
144
148
```yaml
@@ -241,7 +245,18 @@ User:
241
245
- see both examples here [tests/specs/many2many.yaml](tests/specs/many2many.yaml)
242
246
243
247
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:
245
260
246
261
### Adding columns to existing tables
247
262
@@ -256,7 +271,7 @@ Such a migration will fail when the table is not empty:
> add column name string(128) NOT NULL to table {{%company}} ...Exception: SQLSTATE[23502]: Not null violation: 7 ERROR: column "name" contains null values
262
277
@@ -330,6 +345,7 @@ It work on MariaDb.
330
345
```
331
346
332
347
### Handling of `numeric` (#numeric, #MariaDb)
348
+
333
349
precision-default = 10
334
350
scale-default = 2
335
351
@@ -360,6 +376,7 @@ DB-Result = decimal(12,2)
360
376
```
361
377
DB-Result = decimal(10,2)
362
378
379
+
363
380
## Screenshots
364
381
365
382
Gii Generator Form:
@@ -370,6 +387,7 @@ Generated files:
370
387
371
388

372
389
390
+
373
391
# Development
374
392
375
393
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:
0 commit comments