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
* php-openapi/20-consider-openapi-spec-examples-in-faker-code-generation: (28 commits)
Enhance docs
Add test spec file
Handle example
Add docs for `x-no-relation` and create its constant
Fix bug
Refactor
Fix issues + add support for all refs only in oneOf
Add typehint to fn args
Fix count issue for nested array
Fix failing test in PHP >= 8.1
Fix errors 2 + implement custom attribute `x-no-relation`
Fix errors
Fix failing test
Fix failing test
Fix bug
Fix failing test for x_db_type
Implement complex oneOf + fix error 'Creating default object from empty value in PHP'
Complex oneOf - WIP
Implement oneOf and refactor - WIP 3
Implement oneOf and refactor - WIP 2
...
Copy file name to clipboardExpand all lines: README.md
+62-5
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
@@ -317,6 +319,60 @@ Provide custom database table column name in case of relationship column. This w
317
319
- x-fk-column-name: redelivery_of # this will create `redelivery_of` column instead of `redelivery_of_id`
318
320
```
319
321
322
+
### `x-no-relation`
323
+
324
+
To differentiate a component schema property from one-to-many or many-to-many relation in favour of array(json) of
325
+
related objects, `x-no-relation` (type: boolean, default: false) is used.
326
+
327
+
```yaml
328
+
comments:
329
+
type: array
330
+
items:
331
+
$ref: "#/components/schemas/Comment"
332
+
```
333
+
334
+
This will not generate 'comments' column in database migrations. But it will generate `getComments()` relation in Yii model file.
335
+
336
+
In order to make it real database column, extension `x-no-relation` can be used.
337
+
338
+
```yaml
339
+
comments:
340
+
type: array
341
+
x-no-relation: true
342
+
items:
343
+
$ref: "#/components/schemas/Comment"
344
+
```
345
+
346
+
Database column type can be `array`, `json` etc. to store such data.
347
+
348
+
Now if the Comment schema from the above example is
349
+
350
+
```yaml
351
+
Comment:
352
+
properties:
353
+
id:
354
+
type: integer
355
+
content:
356
+
type: string
357
+
```
358
+
359
+
then the value for `comments` can be
360
+
361
+
```json
362
+
[
363
+
{
364
+
"id": 1,
365
+
"content": "Hi there"
366
+
},
367
+
{
368
+
"id": 2,
369
+
"content": "Hi there 2"
370
+
}
371
+
]
372
+
```
373
+
374
+
`x-no-relation`can be only used with OpenAPI schema data type `array`.
375
+
320
376
### `x-route`
321
377
322
378
To customize route (controller ID/action ID) for a path, use custom key `x-route` with value `<controller ID>/<action ID>`. It can be used for non-crud paths. It must be used under HTTP method key but not
@@ -399,8 +455,8 @@ There are two ways for define many-to-many relations:
399
455
### Simple many-to-many without junction model
400
456
401
457
- property name for many-to-many relation should be equal lower-cased, pluralized related schema name
402
-
403
-
- referenced schema should contains mirrored reference to current schema
458
+
459
+
- referenced schema should contain mirrored reference to current schema
404
460
405
461
- migration for junction table can be generated automatically - table name should be [pluralized, lower-cased
406
462
schema_name1]2[pluralized, lower-cased schema name2], in alphabetical order;
@@ -591,12 +647,13 @@ created_at:
591
647
## Assumptions
592
648
593
649
When generating code from an OpenAPI description there are many possible ways to achive a fitting result.
594
-
Thus there are some assumptions and limitations that are currently applied to make this work.
650
+
Thus, there are some assumptions and limitations that are currently applied to make this work.
595
651
Here is a (possibly incomplete) list:
596
652
597
653
- The current implementation works best with OpenAPI description that follows the [JSON:API](https://jsonapi.org/) guidelines.
598
654
- 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
599
-
- 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()`
655
+
- column/field/property with name `id` is considered as Primary Key by this library, and it is automatically handled by
656
+
DB/Yii; so remove it from validation `rules()`
600
657
- 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