@@ -6550,7 +6550,7 @@ public function __construct(string $driver)
6550
6550
],
6551
6551
// source: https://docs.microsoft.com/en-us/sql/connect/jdbc/using-basic-data-types?view=sql-server-2017
6552
6552
'sqlsrv ' => [
6553
- 'varbinary(0 ) ' => 'blob ' ,
6553
+ 'varbinary() ' => 'blob ' ,
6554
6554
'bit ' => 'boolean ' ,
6555
6555
'datetime ' => 'timestamp ' ,
6556
6556
'datetime2 ' => 'timestamp ' ,
@@ -8406,7 +8406,7 @@ public function __construct(ReflectionService $reflection, $base)
8406
8406
{
8407
8407
$ this ->openapi = new OpenApiDefinition ($ base );
8408
8408
$ this ->records = new OpenApiRecordsBuilder ($ this ->openapi , $ reflection );
8409
- $ this ->columns = new OpenApiColumnsBuilder ($ this ->openapi , $ reflection );
8409
+ $ this ->columns = new OpenApiColumnsBuilder ($ this ->openapi );
8410
8410
}
8411
8411
8412
8412
private function getServerUrl (): string
@@ -8426,6 +8426,7 @@ public function build(): OpenApiDefinition
8426
8426
$ this ->openapi ->set ("servers|0|url " , $ this ->getServerUrl ());
8427
8427
}
8428
8428
$ this ->records ->build ();
8429
+ //$this->columns->build();
8429
8430
return $ this ->openapi ;
8430
8431
}
8431
8432
}
@@ -8441,16 +8442,174 @@ public function build(): OpenApiDefinition
8441
8442
class OpenApiColumnsBuilder
8442
8443
{
8443
8444
private $ openapi ;
8444
- private $ reflection ;
8445
+ private $ operations = [
8446
+ 'database ' => [
8447
+ 'read ' => 'get ' ,
8448
+ ],
8449
+ 'table ' => [
8450
+ 'create ' => 'post ' ,
8451
+ 'read ' => 'get ' ,
8452
+ 'update ' => 'put ' , //rename
8453
+ 'delete ' => 'delete ' ,
8454
+ ],
8455
+ 'column ' => [
8456
+ 'create ' => 'post ' ,
8457
+ 'read ' => 'get ' ,
8458
+ 'update ' => 'put ' ,
8459
+ 'delete ' => 'delete ' ,
8460
+ ]
8461
+ ];
8445
8462
8446
- public function __construct (OpenApiDefinition $ openapi, ReflectionService $ reflection )
8463
+ public function __construct (OpenApiDefinition $ openapi )
8447
8464
{
8448
8465
$ this ->openapi = $ openapi ;
8449
- $ this ->reflection = $ reflection ;
8450
8466
}
8451
8467
8452
8468
public function build () /*: void*/
8453
8469
{
8470
+ $ this ->setPaths ();
8471
+ $ this ->openapi ->set ("components|responses|boolSuccess|description " , "boolean indicating success or failure " );
8472
+ $ this ->openapi ->set ("components|responses|boolSuccess|content|application/json|schema|type " , "boolean " );
8473
+ $ this ->setComponentSchema ();
8474
+ $ this ->setComponentResponse ();
8475
+ $ this ->setComponentRequestBody ();
8476
+ $ this ->setComponentParameters ();
8477
+ foreach (array_keys ($ this ->operations ) as $ index => $ type ) {
8478
+ $ this ->setTag ($ index , $ type );
8479
+ }
8480
+ }
8481
+
8482
+ private function setPaths () /*: void*/
8483
+ {
8484
+ foreach (array_keys ($ this ->operations ) as $ type ) {
8485
+ foreach ($ this ->operations [$ type ] as $ operation => $ method ) {
8486
+ $ parameters = [];
8487
+ switch ($ type ) {
8488
+ case 'database ' :
8489
+ $ path = '/columns ' ;
8490
+ break ;
8491
+ case 'table ' :
8492
+ $ path = $ operation == 'create ' ? '/columns ' : '/columns/{table} ' ;
8493
+ break ;
8494
+ case 'column ' :
8495
+ $ path = $ operation == 'create ' ? '/columns/{table} ' : '/columns/{table}/{column} ' ;
8496
+ break ;
8497
+ }
8498
+ if (strpos ($ path , '{table} ' )) {
8499
+ $ parameters [] = 'table ' ;
8500
+ }
8501
+ if (strpos ($ path , '{column} ' )) {
8502
+ $ parameters [] = 'column ' ;
8503
+ }
8504
+ foreach ($ parameters as $ p => $ parameter ) {
8505
+ $ this ->openapi ->set ("paths| $ path| $ method|parameters| $ p| \$ref " , "#/components/parameters/ $ parameter " );
8506
+ }
8507
+ $ operationType = $ operation . ucfirst ($ type );
8508
+ if (in_array ($ operation , ['create ' , 'update ' ])) {
8509
+ $ this ->openapi ->set ("paths| $ path| $ method|requestBody| \$ref " , "#/components/requestBodies/ $ operationType " );
8510
+ }
8511
+ $ this ->openapi ->set ("paths| $ path| $ method|tags|0 " , "$ type " );
8512
+ $ this ->openapi ->set ("paths| $ path| $ method|description " , "$ operation $ type " );
8513
+ switch ($ operation ) {
8514
+ case 'read ' :
8515
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/ $ operationType " );
8516
+ break ;
8517
+ case 'create ' :
8518
+ case 'update ' :
8519
+ case 'delete ' :
8520
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/boolSuccess " );
8521
+ break ;
8522
+ }
8523
+ }
8524
+ }
8525
+ }
8526
+
8527
+ private function setComponentSchema () /*: void*/
8528
+ {
8529
+ foreach (array_keys ($ this ->operations ) as $ type ) {
8530
+ foreach (array_keys ($ this ->operations [$ type ]) as $ operation ) {
8531
+ if ($ operation == 'delete ' ) {
8532
+ continue ;
8533
+ }
8534
+ $ operationType = $ operation . ucfirst ($ type );
8535
+ $ prefix = "components|schemas| $ operationType " ;
8536
+ $ this ->openapi ->set ("$ prefix|type " , "object " );
8537
+ switch ($ type ) {
8538
+ case 'database ' :
8539
+ $ this ->openapi ->set ("$ prefix|properties|tables|type " , 'array ' );
8540
+ $ this ->openapi ->set ("$ prefix|properties|tables|items| \$ref " , "#/components/responses/readTable " );
8541
+ break ;
8542
+ case 'table ' :
8543
+ $ this ->openapi ->set ("$ prefix|properties|name|type " , 'string ' );
8544
+ $ this ->openapi ->set ("$ prefix|properties|type|type " , 'string ' );
8545
+ $ this ->openapi ->set ("$ prefix|properties|columns|type " , 'array ' );
8546
+ $ this ->openapi ->set ("$ prefix|properties|columns|items| \$ref " , "#/components/responses/readColumn " );
8547
+ break ;
8548
+ case 'column ' :
8549
+ $ this ->openapi ->set ("$ prefix|properties|name|type " , 'string ' );
8550
+ $ this ->openapi ->set ("$ prefix|properties|type|type " , 'string ' );
8551
+ $ this ->openapi ->set ("$ prefix|properties|length|type " , 'integer ' );
8552
+ $ this ->openapi ->set ("$ prefix|properties|length|format " , "int64 " );
8553
+ $ this ->openapi ->set ("$ prefix|properties|precision|type " , 'integer ' );
8554
+ $ this ->openapi ->set ("$ prefix|properties|precision|format " , "int64 " );
8555
+ $ this ->openapi ->set ("$ prefix|properties|scale|type " , 'integer ' );
8556
+ $ this ->openapi ->set ("$ prefix|properties|scale|format " , "int64 " );
8557
+ $ this ->openapi ->set ("$ prefix|properties|nullable|type " , 'boolean ' );
8558
+ $ this ->openapi ->set ("$ prefix|properties|pk|type " , 'boolean ' );
8559
+ $ this ->openapi ->set ("$ prefix|properties|fk|type " , 'string ' );
8560
+ break ;
8561
+ }
8562
+ }
8563
+ }
8564
+ }
8565
+
8566
+ private function setComponentResponse () /*: void*/
8567
+ {
8568
+ foreach (array_keys ($ this ->operations ) as $ type ) {
8569
+ foreach (array_keys ($ this ->operations [$ type ]) as $ operation ) {
8570
+ if ($ operation != 'read ' ) {
8571
+ continue ;
8572
+ }
8573
+ $ operationType = $ operation . ucfirst ($ type );
8574
+ $ this ->openapi ->set ("components|responses| $ operationType|description " , "single $ type record " );
8575
+ $ this ->openapi ->set ("components|responses| $ operationType|content|application/json|schema| \$ref " , "#/components/schemas/ $ operationType " );
8576
+ }
8577
+ }
8578
+ }
8579
+
8580
+ private function setComponentRequestBody () /*: void*/
8581
+ {
8582
+ foreach (array_keys ($ this ->operations ) as $ type ) {
8583
+ foreach (array_keys ($ this ->operations [$ type ]) as $ operation ) {
8584
+ if (!in_array ($ operation , ['create ' , 'update ' ])) {
8585
+ continue ;
8586
+ }
8587
+ $ operationType = $ operation . ucfirst ($ type );
8588
+ $ this ->openapi ->set ("components|requestBodies| $ operationType|description " , "single $ type record " );
8589
+ $ this ->openapi ->set ("components|requestBodies| $ operationType|content|application/json|schema| \$ref " , "#/components/schemas/ $ operationType " );
8590
+ }
8591
+ }
8592
+ }
8593
+
8594
+ private function setComponentParameters () /*: void*/
8595
+ {
8596
+ $ this ->openapi ->set ("components|parameters|table|name " , "table " );
8597
+ $ this ->openapi ->set ("components|parameters|table|in " , "path " );
8598
+ $ this ->openapi ->set ("components|parameters|table|schema|type " , "string " );
8599
+ $ this ->openapi ->set ("components|parameters|table|description " , "table name " );
8600
+ $ this ->openapi ->set ("components|parameters|table|required " , true );
8601
+
8602
+ $ this ->openapi ->set ("components|parameters|column|name " , "column " );
8603
+ $ this ->openapi ->set ("components|parameters|column|in " , "path " );
8604
+ $ this ->openapi ->set ("components|parameters|column|schema|type " , "string " );
8605
+ $ this ->openapi ->set ("components|parameters|column|description " , "column name " );
8606
+ $ this ->openapi ->set ("components|parameters|column|required " , true );
8607
+ }
8608
+
8609
+ private function setTag (int $ index , string $ type ) /*: void*/
8610
+ {
8611
+ $ this ->openapi ->set ("tags| $ index|name " , "$ type " );
8612
+ $ this ->openapi ->set ("tags| $ index|description " , "$ type operations " );
8454
8613
}
8455
8614
}
8456
8615
}
0 commit comments