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.
- Add docs to setup this project locally + fix#98 + enhance docs
- Enhance all code generation for x-db-type
#119 . E.g. x-db-type should
be reflected in model validation rules() + faker and other place where
relevant. PR: SOHELAHMED7#17
- SOHELAHMED7#15
'generateMigrations' => false # this config can also be applied in CLI command
69
+
],
63
70
],
64
71
];
65
72
}
@@ -71,7 +78,7 @@ To use the web generator, open `index.php?r=gii` and select the `REST API Genera
71
78
72
79
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](https://github.com/cebe/php-openapi/) for supported formats).
73
80
74
-
Run `./yii gii/api --help` for all options.
81
+
Run `./yii gii/api --help` for all options. Example: Disable generation of migrations files `./yii gii/api --generateMigrations=0`
75
82
76
83
See [Petstore example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml) for example OpenAPI spec.
77
84
@@ -198,11 +205,12 @@ created_at:
198
205
199
206
Also see: https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html
200
207
201
-
### Many-to-Many relation definition
208
+
209
+
## Many-to-Many relation definition
202
210
203
211
There are two ways for define many-to-many relations:
204
212
205
-
#### Simple many-to-many without junction model
213
+
### Simple many-to-many without junction model
206
214
207
215
- property name for many-to-many relation should be equal lower-cased, pluralized related schema name
208
216
@@ -231,7 +239,7 @@ Tag:
231
239
$ref: '#/components/schemas/Post'
232
240
```
233
241
234
-
#### Many-to-many with junction model
242
+
### Many-to-many with junction model
235
243
236
244
This way allowed creating multiple many-to-many relations between to models
237
245
@@ -274,45 +282,7 @@ User:
274
282
- see both examples here [tests/specs/many2many.yaml](tests/specs/many2many.yaml)
275
283
276
284
277
-
## Assumptions
278
-
279
-
When generating code from an OpenAPI description there are many possible ways to achive a fitting result.
280
-
Thus there are some assumptions and limitations that are currently applied to make this work.
281
-
Here is a (possibly incomplete) list:
282
-
283
-
- The current implementation works best with OpenAPI description that follows the [JSON:API](https://jsonapi.org/) guidelines.
284
-
- 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
285
-
- 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()`
286
-
- 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.
287
-
288
-
Other things to keep in mind:
289
-
290
-
### Adding columns to existing tables
291
-
292
-
When adding new fields in the API models, new migrations will be generated to add these fields to the table.
293
-
For a project that is already in production, it should be considered to adjust the generated migration to add default
294
-
values for existing data records.
295
-
296
-
One case where this is important is the addition of a new column with `NOT NULL` contraint, which does not provide a default value.
297
-
Such a migration will fail when the table is not empty:
`NOT NULL` in DB migrations is determined by `nullable` and `required` properties of the OpenAPI schema.
318
288
e.g. attribute = 'my_property'.
@@ -360,7 +330,7 @@ e.g. attribute = 'my_property'.
360
330
nullable: false
361
331
```
362
332
363
-
### Handling of `enum` (#enum)
333
+
## Handling of `enum` (#enum)
364
334
It works on all 3 DB: MySQL, MariaDb and PgSQL.
365
335
366
336
```yaml
@@ -375,7 +345,7 @@ It works on all 3 DB: MySQL, MariaDb and PgSQL.
375
345
376
346
Note: Change in enum values are not very simple. For Mysql and Mariadb, migrations will be generated but in many cases custom modification in it are required. For Pgsql migrations for change in enum values will not be generated. It should be handled manually.
377
347
378
-
### Handling of `numeric` (#numeric, #MariaDb)
348
+
## Handling of `numeric` (#numeric, #MariaDb)
379
349
380
350
precision-default = 10
381
351
scale-default = 2
@@ -408,6 +378,44 @@ DB-Result = decimal(12,2)
408
378
DB-Result = decimal(10,2)
409
379
410
380
381
+
## Assumptions
382
+
383
+
When generating code from an OpenAPI description there are many possible ways to achive a fitting result.
384
+
Thus there are some assumptions and limitations that are currently applied to make this work.
385
+
Here is a (possibly incomplete) list:
386
+
387
+
- The current implementation works best with OpenAPI description that follows the [JSON:API](https://jsonapi.org/) guidelines.
388
+
- 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
389
+
- 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()`
390
+
- 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.
391
+
392
+
Other things to keep in mind:
393
+
394
+
### Adding columns to existing tables
395
+
396
+
When adding new fields in the API models, new migrations will be generated to add these fields to the table.
397
+
For a project that is already in production, it should be considered to adjust the generated migration to add default
398
+
values for existing data records.
399
+
400
+
One case where this is important is the addition of a new column with `NOT NULL` contraint, which does not provide a default value.
401
+
Such a migration will fail when the table is not empty:
There commands are available to develop and check the tests. It is available inside the Docker container. To enter into bash shell of container, run `make cli` .
432
+
To contribute or play around, steps to set up this project locally are:
# to check everything is setup up correctly ensure all tests passes
445
+
./vendor/bin/phpunit
446
+
447
+
# create new branch from master and Happy contributing!
448
+
```
449
+
450
+
These commands are available to develop and check the tests. It is available inside the Docker container. To enter into bash shell of container, run `make cli` .
0 commit comments