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
Copy file name to clipboardExpand all lines: README.md
+60-5Lines changed: 60 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,9 @@ return $config;
76
76
77
77
To use the web generator, open `index.php?r=gii` and select the `REST API Generator`.
78
78
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 [php-openapi/php-openapi](https://github.com/php-openapi/php-openapi/) for supported formats).
79
+
On console, you can run the generator with `./yii gii/api --openApiPath=@app/openapi.yaml`. Where `@app/openapi.yaml`
80
+
should be the absolute path to your OpenAPI spec file. This can be JSON as well as YAML (see
81
+
also [php-openapi/php-openapi](https://github.com/php-openapi/php-openapi/) for supported formats).
80
82
81
83
Run `./yii gii/api --help` for all options. Example: Disable generation of migrations files `./yii gii/api --generateMigrations=0`
82
84
@@ -311,15 +313,67 @@ Provide custom database table column name in case of relationship column. This w
311
313
312
314
### `x-no-relation`
313
315
316
+
To differentiate a component schema property from one-to-many or many-to-many relation in favour of array(json) of
317
+
related objects, `x-no-relation` is used.
318
+
319
+
```yaml
320
+
comments:
321
+
type: array
322
+
items:
323
+
$ref: "#/components/schemas/Comment"
324
+
```
325
+
326
+
This will not generate 'comments' column in database migrations. But it will generate `getComments()` relation in model.
327
+
328
+
In order to make it real database column, extension `x-no-relation` can be used.
329
+
330
+
```yaml
331
+
comments:
332
+
type: array
333
+
x-no-relation: true
334
+
items:
335
+
$ref: "#/components/schemas/Comment"
336
+
```
337
+
338
+
Database column type can be `array`, `json` etc. to store such data.
339
+
340
+
Now if the Comment schema from the above example is
341
+
342
+
```yaml
343
+
Comment:
344
+
properties:
345
+
id:
346
+
type: integer
347
+
content:
348
+
type: string
349
+
```
350
+
351
+
then the value can be
352
+
353
+
```json
354
+
[
355
+
{
356
+
"id": 1,
357
+
"content": "Hi there"
358
+
},
359
+
{
360
+
"id": 2,
361
+
"content": "Hi there 2"
362
+
}
363
+
]
364
+
```
365
+
366
+
At this moment, `x-no-relation` can be only used with OpenAPI schema data type `array`.
367
+
314
368
## Many-to-Many relation definition
315
369
316
370
There are two ways for define many-to-many relations:
317
371
318
372
### Simple many-to-many without junction model
319
373
320
374
- property name for many-to-many relation should be equal lower-cased, pluralized related schema name
321
-
322
-
- referenced schema should contains mirrored reference to current schema
375
+
376
+
- referenced schema should contain mirrored reference to current schema
323
377
324
378
- migration for junction table can be generated automatically - table name should be [pluralized, lower-cased
325
379
schema_name1]2[pluralized, lower-cased schema name2], in alphabetical order;
@@ -510,12 +564,13 @@ created_at:
510
564
## Assumptions
511
565
512
566
When generating code from an OpenAPI description there are many possible ways to achive a fitting result.
513
-
Thus there are some assumptions and limitations that are currently applied to make this work.
567
+
Thus, there are some assumptions and limitations that are currently applied to make this work.
514
568
Here is a (possibly incomplete) list:
515
569
516
570
- The current implementation works best with OpenAPI description that follows the [JSON:API](https://jsonapi.org/) guidelines.
517
571
- 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
518
-
- 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()`
572
+
- column/field/property with name `id` is considered as Primary Key by this library, and it is automatically handled by
573
+
DB/Yii; so remove it from validation `rules()`
519
574
- 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.
0 commit comments