Skip to content

Commit 167df45

Browse files
committed
fix for #755
1 parent 53acadb commit 167df45

File tree

4 files changed

+285
-0
lines changed

4 files changed

+285
-0
lines changed

api.include.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9030,6 +9030,7 @@ public function __construct(ReflectionService $reflection, array $base, array $c
90309030
$this->openapi = new OpenApiDefinition($base);
90319031
$this->records = in_array('records', $controllers) ? new OpenApiRecordsBuilder($this->openapi, $reflection) : null;
90329032
$this->columns = in_array('columns', $controllers) ? new OpenApiColumnsBuilder($this->openapi) : null;
9033+
$this->status = in_array('status', $controllers) ? new OpenApiStatusBuilder($this->openapi) : null;
90339034
$this->builders = array();
90349035
foreach ($builders as $className) {
90359036
$this->builders[] = new $className($this->openapi, $reflection);
@@ -9058,6 +9059,9 @@ public function build(): OpenApiDefinition
90589059
if ($this->columns) {
90599060
$this->columns->build();
90609061
}
9062+
if ($this->status) {
9063+
$this->status->build();
9064+
}
90619065
foreach ($this->builders as $builder) {
90629066
$builder->build();
90639067
}
@@ -9703,6 +9707,97 @@ public function get(): OpenApiDefinition
97039707
}
97049708
}
97059709

9710+
// file: src/Tqdev/PhpCrudApi/OpenApi/OpenApiStatusBuilder.php
9711+
namespace Tqdev\PhpCrudApi\OpenApi {
9712+
9713+
use Tqdev\PhpCrudApi\OpenApi\OpenApiDefinition;
9714+
9715+
class OpenApiStatusBuilder
9716+
{
9717+
private $openapi;
9718+
private $operations = [
9719+
'status' => [
9720+
'up' => 'get',
9721+
'ping' => 'get',
9722+
],
9723+
];
9724+
9725+
public function __construct(OpenApiDefinition $openapi)
9726+
{
9727+
$this->openapi = $openapi;
9728+
}
9729+
9730+
public function build() /*: void*/
9731+
{
9732+
$this->setPaths();
9733+
$this->openapi->set("components|responses|boolSuccess|description", "boolean indicating success or failure");
9734+
$this->openapi->set("components|responses|boolSuccess|content|application/json|schema|type", "boolean");
9735+
$this->setComponentSchema();
9736+
$this->setComponentResponse();
9737+
foreach (array_keys($this->operations) as $index => $type) {
9738+
$this->setTag($index, $type);
9739+
}
9740+
}
9741+
9742+
private function setPaths() /*: void*/
9743+
{
9744+
foreach ($this->operations as $type => $operationPair) {
9745+
foreach ($operationPair as $operation => $method) {
9746+
$path = "/$type/$operation";
9747+
$operationType = $operation . ucfirst($type);
9748+
$this->openapi->set("paths|$path|$method|tags|0", "$type");
9749+
$this->openapi->set("paths|$path|$method|operationId", "$operation" . "_" . "$type");
9750+
$this->openapi->set("paths|$path|$method|description", "Request API '$type' status");
9751+
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operationType");
9752+
9753+
}
9754+
}
9755+
}
9756+
9757+
private function setComponentSchema() /*: void*/
9758+
{
9759+
foreach ($this->operations as $type => $operationPair) {
9760+
foreach ($operationPair as $operation => $method) {
9761+
$operationType = $operation . ucfirst($type);
9762+
$prefix = "components|schemas|$operationType";
9763+
$this->openapi->set("$prefix|type", "object");
9764+
switch ($type) {
9765+
case 'ping':
9766+
$this->openapi->set("$prefix|required", ['db', 'cache']);
9767+
$this->openapi->set("$prefix|properties|db|type", 'integer');
9768+
$this->openapi->set("$prefix|properties|db|format", "int64");
9769+
$this->openapi->set("$prefix|properties|cache|type", 'integer');
9770+
$this->openapi->set("$prefix|properties|cache|format", "int64");
9771+
break;
9772+
case 'up':
9773+
$this->openapi->set("$prefix|required", ['db', 'cache']);
9774+
$this->openapi->set("$prefix|properties|db|type", 'boolean');
9775+
$this->openapi->set("$prefix|properties|cache|type", 'boolean');
9776+
break;
9777+
}
9778+
}
9779+
}
9780+
}
9781+
9782+
private function setComponentResponse() /*: void*/
9783+
{
9784+
foreach ($this->operations as $type => $operationPair) {
9785+
foreach ($operationPair as $operation => $method) {
9786+
$operationType = $operation . ucfirst($type);
9787+
$this->openapi->set("components|responses|$operationType|description", "status $type record");
9788+
$this->openapi->set("components|responses|$operationType|content|application/json|schema|\$ref", "#/components/schemas/$operationType");
9789+
}
9790+
}
9791+
}
9792+
9793+
private function setTag(int $index, string $type) /*: void*/
9794+
{
9795+
$this->openapi->set("tags|$index|name", "$type");
9796+
$this->openapi->set("tags|$index|description", "$type operations");
9797+
}
9798+
}
9799+
}
9800+
97069801
// file: src/Tqdev/PhpCrudApi/Record/Condition/AndCondition.php
97079802
namespace Tqdev\PhpCrudApi\Record\Condition {
97089803

api.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9030,6 +9030,7 @@ public function __construct(ReflectionService $reflection, array $base, array $c
90309030
$this->openapi = new OpenApiDefinition($base);
90319031
$this->records = in_array('records', $controllers) ? new OpenApiRecordsBuilder($this->openapi, $reflection) : null;
90329032
$this->columns = in_array('columns', $controllers) ? new OpenApiColumnsBuilder($this->openapi) : null;
9033+
$this->status = in_array('status', $controllers) ? new OpenApiStatusBuilder($this->openapi) : null;
90339034
$this->builders = array();
90349035
foreach ($builders as $className) {
90359036
$this->builders[] = new $className($this->openapi, $reflection);
@@ -9058,6 +9059,9 @@ public function build(): OpenApiDefinition
90589059
if ($this->columns) {
90599060
$this->columns->build();
90609061
}
9062+
if ($this->status) {
9063+
$this->status->build();
9064+
}
90619065
foreach ($this->builders as $builder) {
90629066
$builder->build();
90639067
}
@@ -9703,6 +9707,97 @@ public function get(): OpenApiDefinition
97039707
}
97049708
}
97059709

9710+
// file: src/Tqdev/PhpCrudApi/OpenApi/OpenApiStatusBuilder.php
9711+
namespace Tqdev\PhpCrudApi\OpenApi {
9712+
9713+
use Tqdev\PhpCrudApi\OpenApi\OpenApiDefinition;
9714+
9715+
class OpenApiStatusBuilder
9716+
{
9717+
private $openapi;
9718+
private $operations = [
9719+
'status' => [
9720+
'up' => 'get',
9721+
'ping' => 'get',
9722+
],
9723+
];
9724+
9725+
public function __construct(OpenApiDefinition $openapi)
9726+
{
9727+
$this->openapi = $openapi;
9728+
}
9729+
9730+
public function build() /*: void*/
9731+
{
9732+
$this->setPaths();
9733+
$this->openapi->set("components|responses|boolSuccess|description", "boolean indicating success or failure");
9734+
$this->openapi->set("components|responses|boolSuccess|content|application/json|schema|type", "boolean");
9735+
$this->setComponentSchema();
9736+
$this->setComponentResponse();
9737+
foreach (array_keys($this->operations) as $index => $type) {
9738+
$this->setTag($index, $type);
9739+
}
9740+
}
9741+
9742+
private function setPaths() /*: void*/
9743+
{
9744+
foreach ($this->operations as $type => $operationPair) {
9745+
foreach ($operationPair as $operation => $method) {
9746+
$path = "/$type/$operation";
9747+
$operationType = $operation . ucfirst($type);
9748+
$this->openapi->set("paths|$path|$method|tags|0", "$type");
9749+
$this->openapi->set("paths|$path|$method|operationId", "$operation" . "_" . "$type");
9750+
$this->openapi->set("paths|$path|$method|description", "Request API '$type' status");
9751+
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operationType");
9752+
9753+
}
9754+
}
9755+
}
9756+
9757+
private function setComponentSchema() /*: void*/
9758+
{
9759+
foreach ($this->operations as $type => $operationPair) {
9760+
foreach ($operationPair as $operation => $method) {
9761+
$operationType = $operation . ucfirst($type);
9762+
$prefix = "components|schemas|$operationType";
9763+
$this->openapi->set("$prefix|type", "object");
9764+
switch ($type) {
9765+
case 'ping':
9766+
$this->openapi->set("$prefix|required", ['db', 'cache']);
9767+
$this->openapi->set("$prefix|properties|db|type", 'integer');
9768+
$this->openapi->set("$prefix|properties|db|format", "int64");
9769+
$this->openapi->set("$prefix|properties|cache|type", 'integer');
9770+
$this->openapi->set("$prefix|properties|cache|format", "int64");
9771+
break;
9772+
case 'up':
9773+
$this->openapi->set("$prefix|required", ['db', 'cache']);
9774+
$this->openapi->set("$prefix|properties|db|type", 'boolean');
9775+
$this->openapi->set("$prefix|properties|cache|type", 'boolean');
9776+
break;
9777+
}
9778+
}
9779+
}
9780+
}
9781+
9782+
private function setComponentResponse() /*: void*/
9783+
{
9784+
foreach ($this->operations as $type => $operationPair) {
9785+
foreach ($operationPair as $operation => $method) {
9786+
$operationType = $operation . ucfirst($type);
9787+
$this->openapi->set("components|responses|$operationType|description", "status $type record");
9788+
$this->openapi->set("components|responses|$operationType|content|application/json|schema|\$ref", "#/components/schemas/$operationType");
9789+
}
9790+
}
9791+
}
9792+
9793+
private function setTag(int $index, string $type) /*: void*/
9794+
{
9795+
$this->openapi->set("tags|$index|name", "$type");
9796+
$this->openapi->set("tags|$index|description", "$type operations");
9797+
}
9798+
}
9799+
}
9800+
97069801
// file: src/Tqdev/PhpCrudApi/Record/Condition/AndCondition.php
97079802
namespace Tqdev\PhpCrudApi\Record\Condition {
97089803

src/Tqdev/PhpCrudApi/OpenApi/OpenApiBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __construct(ReflectionService $reflection, array $base, array $c
1717
$this->openapi = new OpenApiDefinition($base);
1818
$this->records = in_array('records', $controllers) ? new OpenApiRecordsBuilder($this->openapi, $reflection) : null;
1919
$this->columns = in_array('columns', $controllers) ? new OpenApiColumnsBuilder($this->openapi) : null;
20+
$this->status = in_array('status', $controllers) ? new OpenApiStatusBuilder($this->openapi) : null;
2021
$this->builders = array();
2122
foreach ($builders as $className) {
2223
$this->builders[] = new $className($this->openapi, $reflection);
@@ -45,6 +46,9 @@ public function build(): OpenApiDefinition
4546
if ($this->columns) {
4647
$this->columns->build();
4748
}
49+
if ($this->status) {
50+
$this->status->build();
51+
}
4852
foreach ($this->builders as $builder) {
4953
$builder->build();
5054
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace Tqdev\PhpCrudApi\OpenApi;
4+
5+
use Tqdev\PhpCrudApi\OpenApi\OpenApiDefinition;
6+
7+
class OpenApiStatusBuilder
8+
{
9+
private $openapi;
10+
private $operations = [
11+
'status' => [
12+
'up' => 'get',
13+
'ping' => 'get',
14+
],
15+
];
16+
17+
18+
public function __construct(OpenApiDefinition $openapi)
19+
{
20+
$this->openapi = $openapi;
21+
}
22+
23+
public function build() /*: void*/
24+
{
25+
$this->setPaths();
26+
$this->openapi->set("components|responses|boolSuccess|description", "boolean indicating success or failure");
27+
$this->openapi->set("components|responses|boolSuccess|content|application/json|schema|type", "boolean");
28+
$this->setComponentSchema();
29+
$this->setComponentResponse();
30+
foreach (array_keys($this->operations) as $index => $type) {
31+
$this->setTag($index, $type);
32+
}
33+
}
34+
35+
private function setPaths() /*: void*/
36+
{
37+
foreach ($this->operations as $type => $operationPair) {
38+
foreach ($operationPair as $operation => $method) {
39+
$path = "/$type/$operation";
40+
$operationType = $operation . ucfirst($type);
41+
$this->openapi->set("paths|$path|$method|tags|0", "$type");
42+
$this->openapi->set("paths|$path|$method|operationId", "$operation" . "_" . "$type");
43+
$this->openapi->set("paths|$path|$method|description", "Request API '$operation' status");
44+
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operationType");
45+
46+
}
47+
}
48+
}
49+
50+
private function setComponentSchema() /*: void*/
51+
{
52+
foreach ($this->operations as $type => $operationPair) {
53+
foreach ($operationPair as $operation => $method) {
54+
$operationType = $operation . ucfirst($type);
55+
$prefix = "components|schemas|$operationType";
56+
$this->openapi->set("$prefix|type", "object");
57+
switch ($operation) {
58+
case 'ping':
59+
$this->openapi->set("$prefix|required", ['db', 'cache']);
60+
$this->openapi->set("$prefix|properties|db|type", 'integer');
61+
$this->openapi->set("$prefix|properties|db|format", "int64");
62+
$this->openapi->set("$prefix|properties|cache|type", 'integer');
63+
$this->openapi->set("$prefix|properties|cache|format", "int64");
64+
break;
65+
case 'up':
66+
$this->openapi->set("$prefix|required", ['db', 'cache']);
67+
$this->openapi->set("$prefix|properties|db|type", 'boolean');
68+
$this->openapi->set("$prefix|properties|cache|type", 'boolean');
69+
break;
70+
}
71+
}
72+
}
73+
}
74+
75+
private function setComponentResponse() /*: void*/
76+
{
77+
foreach ($this->operations as $type => $operationPair) {
78+
foreach ($operationPair as $operation => $method) {
79+
$operationType = $operation . ucfirst($type);
80+
$this->openapi->set("components|responses|$operationType|description", "$operation status record");
81+
$this->openapi->set("components|responses|$operationType|content|application/json|schema|\$ref", "#/components/schemas/$operationType");
82+
}
83+
}
84+
}
85+
86+
private function setTag(int $index, string $type) /*: void*/
87+
{
88+
$this->openapi->set("tags|$index|name", "$type");
89+
$this->openapi->set("tags|$index|description", "$type operations");
90+
}
91+
}

0 commit comments

Comments
 (0)