@@ -3356,8 +3356,19 @@ public function build(): OpenApiDefinition
3356
3356
foreach ($ tableNames as $ tableName ) {
3357
3357
$ this ->setPath ($ tableName );
3358
3358
}
3359
+ $ this ->openapi ->set ("components|responses|pk_integer|description " , "inserted primary key value (integer) " );
3360
+ $ this ->openapi ->set ("components|responses|pk_integer|content|application/json|schema|type " , "integer " );
3361
+ $ this ->openapi ->set ("components|responses|pk_integer|content|application/json|schema|format " , "int64 " );
3362
+ $ this ->openapi ->set ("components|responses|pk_string|description " , "inserted primary key value (string) " );
3363
+ $ this ->openapi ->set ("components|responses|pk_string|content|application/json|schema|type " , "string " );
3364
+ $ this ->openapi ->set ("components|responses|pk_string|content|application/json|schema|format " , "uuid " );
3365
+ $ this ->openapi ->set ("components|responses|rows_affected|description " , "number of rows affected (integer) " );
3366
+ $ this ->openapi ->set ("components|responses|rows_affected|content|application/json|schema|type " , "integer " );
3367
+ $ this ->openapi ->set ("components|responses|rows_affected|content|application/json|schema|format " , "int64 " );
3359
3368
foreach ($ tableNames as $ tableName ) {
3360
3369
$ this ->setComponentSchema ($ tableName );
3370
+ $ this ->setComponentResponse ($ tableName );
3371
+ $ this ->setComponentRequestBody ($ tableName );
3361
3372
}
3362
3373
$ this ->setComponentParameters ();
3363
3374
foreach ($ tableNames as $ index => $ tableName ) {
@@ -3372,33 +3383,74 @@ private function setPath(String $tableName) /*: void*/
3372
3383
$ pk = $ table ->getPk ();
3373
3384
$ pkName = $ pk ? $ pk ->getName () : '' ;
3374
3385
foreach ($ this ->operations as $ operation => $ method ) {
3386
+ if (!$ pkName && $ operation != 'list ' ) {
3387
+ continue ;
3388
+ }
3375
3389
if (in_array ($ operation , ['list ' , 'create ' ])) {
3376
3390
$ path = sprintf ('/records/%s ' , $ tableName );
3377
3391
} else {
3378
- if (!$ pkName ) {
3379
- continue ;
3380
- }
3381
3392
$ path = sprintf ('/records/%s/{%s} ' , $ tableName , $ pkName );
3382
3393
$ this ->openapi ->set ("paths| $ path| $ method|parameters|0| \$ref " , "#/components/parameters/pk " );
3383
3394
}
3395
+ if (in_array ($ operation , ['create ' , 'update ' ])) {
3396
+ $ this ->openapi ->set ("paths| $ path| $ method|requestBody| \$ref " , "#/components/requestBodies/single_ " . urlencode ($ tableName ));
3397
+ }
3384
3398
$ this ->openapi ->set ("paths| $ path| $ method|tags|0 " , "$ tableName " );
3385
3399
$ this ->openapi ->set ("paths| $ path| $ method|description " , "$ operation $ tableName " );
3386
- $ this ->openapi ->set ("paths| $ path| $ method|responses|200|description " , "$ operation $ tableName succeeded " );
3400
+ switch ($ operation ) {
3401
+ case 'list ' :
3402
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/list_of_ " . urlencode ($ tableName ));
3403
+ break ;
3404
+ case 'create ' :
3405
+ if ($ pk ->getType () == 'integer ' ) {
3406
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/pk_integer " );
3407
+ } else {
3408
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/pk_string " );
3409
+ }
3410
+ break ;
3411
+ case 'read ' :
3412
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/single_ " . urlencode ($ tableName ));
3413
+ break ;
3414
+ case 'update ' :
3415
+ case 'delete ' :
3416
+ case 'increment ' :
3417
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/rows_affected " );
3418
+ break ;
3419
+ }
3420
+
3387
3421
}
3388
3422
}
3389
3423
3390
3424
private function setComponentSchema (String $ tableName ) /*: void*/
3391
3425
{
3392
- $ this ->openapi ->set ("components|schemas| $ tableName|type " , "object " );
3426
+ $ this ->openapi ->set ("components|schemas|single_ $ tableName|type " , "object " );
3393
3427
$ table = $ this ->reflection ->getTable ($ tableName );
3394
3428
foreach ($ table ->columnNames () as $ columnName ) {
3395
3429
$ column = $ table ->get ($ columnName );
3396
3430
$ properties = $ this ->types [$ column ->getType ()];
3397
3431
foreach ($ properties as $ key => $ value ) {
3398
- $ this ->openapi ->set ("components|schemas| $ tableName|properties| $ columnName| $ key " , $ value );
3432
+ $ this ->openapi ->set ("components|schemas|single_ $ tableName|properties| $ columnName| $ key " , $ value );
3399
3433
}
3400
-
3401
3434
}
3435
+ $ this ->openapi ->set ("components|schemas|list_of_ $ tableName|type " , "object " );
3436
+ $ this ->openapi ->set ("components|schemas|list_of_ $ tableName|properties|count|type " , "integer " );
3437
+ $ this ->openapi ->set ("components|schemas|list_of_ $ tableName|properties|count|format " , "int64 " );
3438
+ $ this ->openapi ->set ("components|schemas|list_of_ $ tableName|properties|records|type " , "array " );
3439
+ $ this ->openapi ->set ("components|schemas|list_of_ $ tableName|properties|records|items| \$ref " , "#/components/schemas/single_ " . urlencode ($ tableName ));
3440
+ }
3441
+
3442
+ private function setComponentResponse (String $ tableName ) /*: void*/
3443
+ {
3444
+ $ this ->openapi ->set ("components|responses|single_ $ tableName|description " , "single $ tableName record " );
3445
+ $ this ->openapi ->set ("components|responses|single_ $ tableName|content|application/json|schema| \$ref " , "#/components/schemas/single_ " . urlencode ($ tableName ));
3446
+ $ this ->openapi ->set ("components|responses|list_of_ $ tableName|description " , "list of $ tableName records " );
3447
+ $ this ->openapi ->set ("components|responses|list_of_ $ tableName|content|application/json|schema| \$ref " , "#/components/schemas/list_of_ " . urlencode ($ tableName ));
3448
+ }
3449
+
3450
+ private function setComponentRequestBody (String $ tableName ) /*: void*/
3451
+ {
3452
+ $ this ->openapi ->set ("components|requestBodies|single_ $ tableName|description " , "single $ tableName record " );
3453
+ $ this ->openapi ->set ("components|requestBodies|single_ $ tableName|content|application/json|schema| \$ref " , "#/components/schemas/single_ " . urlencode ($ tableName ));
3402
3454
}
3403
3455
3404
3456
private function setComponentParameters () /*: void*/
0 commit comments