@@ -3356,8 +3356,19 @@ public function build(): OpenApiDefinition
33563356 foreach ($ tableNames as $ tableName ) {
33573357 $ this ->setPath ($ tableName );
33583358 }
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 " );
33593368 foreach ($ tableNames as $ tableName ) {
33603369 $ this ->setComponentSchema ($ tableName );
3370+ $ this ->setComponentResponse ($ tableName );
3371+ $ this ->setComponentRequestBody ($ tableName );
33613372 }
33623373 $ this ->setComponentParameters ();
33633374 foreach ($ tableNames as $ index => $ tableName ) {
@@ -3372,33 +3383,74 @@ private function setPath(String $tableName) /*: void*/
33723383 $ pk = $ table ->getPk ();
33733384 $ pkName = $ pk ? $ pk ->getName () : '' ;
33743385 foreach ($ this ->operations as $ operation => $ method ) {
3386+ if (!$ pkName && $ operation != 'list ' ) {
3387+ continue ;
3388+ }
33753389 if (in_array ($ operation , ['list ' , 'create ' ])) {
33763390 $ path = sprintf ('/records/%s ' , $ tableName );
33773391 } else {
3378- if (!$ pkName ) {
3379- continue ;
3380- }
33813392 $ path = sprintf ('/records/%s/{%s} ' , $ tableName , $ pkName );
33823393 $ this ->openapi ->set ("paths| $ path| $ method|parameters|0| \$ref " , "#/components/parameters/pk " );
33833394 }
3395+ if (in_array ($ operation , ['create ' , 'update ' ])) {
3396+ $ this ->openapi ->set ("paths| $ path| $ method|requestBody| \$ref " , "#/components/requestBodies/single_ " . urlencode ($ tableName ));
3397+ }
33843398 $ this ->openapi ->set ("paths| $ path| $ method|tags|0 " , "$ tableName " );
33853399 $ 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+
33873421 }
33883422 }
33893423
33903424 private function setComponentSchema (String $ tableName ) /*: void*/
33913425 {
3392- $ this ->openapi ->set ("components|schemas| $ tableName|type " , "object " );
3426+ $ this ->openapi ->set ("components|schemas|single_ $ tableName|type " , "object " );
33933427 $ table = $ this ->reflection ->getTable ($ tableName );
33943428 foreach ($ table ->columnNames () as $ columnName ) {
33953429 $ column = $ table ->get ($ columnName );
33963430 $ properties = $ this ->types [$ column ->getType ()];
33973431 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 );
33993433 }
3400-
34013434 }
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 ));
34023454 }
34033455
34043456 private function setComponentParameters () /*: void*/
0 commit comments