Skip to content

Commit 5a32a29

Browse files
committed
Improve openapi
1 parent 2e194f4 commit 5a32a29

File tree

2 files changed

+43
-37
lines changed

2 files changed

+43
-37
lines changed

api.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,14 +3328,14 @@ class OpenApiBuilder
33283328
'increment' => 'patch',
33293329
];
33303330
private $types = [
3331-
'integer' => 'integer',
3332-
'varchar' => 'string',
3333-
'blob' => 'string',
3334-
'clob' => 'string',
3335-
'decimal' => 'string',
3336-
'timestamp' => 'string',
3337-
'geometry' => 'string',
3338-
'boolean' => 'boolean',
3331+
'integer' => ['type' => 'integer', 'format' => 'int64'],
3332+
'varchar' => ['type' => 'string'],
3333+
'blob' => ['type' => 'string'],
3334+
'clob' => ['type' => 'string'],
3335+
'decimal' => ['type' => 'string'],
3336+
'timestamp' => ['type' => 'string'],
3337+
'geometry' => ['type' => 'string'],
3338+
'boolean' => ['type' => 'boolean'],
33393339
];
33403340

33413341
public function __construct(ReflectionService $reflection, $base)
@@ -3349,18 +3349,18 @@ public function build(): OpenApiDefinition
33493349
$this->openapi->set("openapi", "3.0.0");
33503350
$tableNames = $this->reflection->getTableNames();
33513351
foreach ($tableNames as $tableName) {
3352-
$this->setPath("paths", $tableName);
3352+
$this->setPath($tableName);
33533353
}
33543354
foreach ($tableNames as $tableName) {
3355-
$this->setComponentSchema("components|schemas", $tableName);
3355+
$this->setComponentSchema($tableName);
33563356
}
33573357
foreach ($tableNames as $index => $tableName) {
3358-
$this->setTag("tags", $index, $tableName);
3358+
$this->setTag($index, $tableName);
33593359
}
33603360
return $this->openapi;
33613361
}
33623362

3363-
private function setPath(String $prefix, String $tableName) /*: void*/
3363+
private function setPath(String $tableName) /*: void*/
33643364
{
33653365
$table = $this->reflection->getTable($tableName);
33663366
$pk = $table->getPk();
@@ -3373,32 +3373,35 @@ private function setPath(String $prefix, String $tableName) /*: void*/
33733373
continue;
33743374
}
33753375
$path = sprintf('/records/%s/{%s}', $tableName, $pkName);
3376-
$this->openapi->set("$prefix|$path|$method|parameters|0|name", "id");
3377-
$this->openapi->set("$prefix|$path|$method|parameters|0|in", "path");
3378-
$this->openapi->set("$prefix|$path|$method|parameters|0|schema|type", "string");
3379-
$this->openapi->set("$prefix|$path|$method|parameters|0|required", true);
3376+
$this->openapi->set("paths|$path|$method|parameters|0|name", "id");
3377+
$this->openapi->set("paths|$path|$method|parameters|0|in", "path");
3378+
$this->openapi->set("paths|$path|$method|parameters|0|schema|type", "string");
3379+
$this->openapi->set("paths|$path|$method|parameters|0|required", true);
33803380
}
3381-
$this->openapi->set("$prefix|$path|$method|tags|0", "$tableName");
3382-
$this->openapi->set("$prefix|$path|$method|description", "$operation $tableName");
3383-
$this->openapi->set("$prefix|$path|$method|responses|200|description", "$operation $tableName succeeded");
3381+
$this->openapi->set("paths|$path|$method|tags|0", "$tableName");
3382+
$this->openapi->set("paths|$path|$method|description", "$operation $tableName");
3383+
$this->openapi->set("paths|$path|$method|responses|200|description", "$operation $tableName succeeded");
33843384
}
33853385
}
33863386

3387-
private function setComponentSchema(String $prefix, String $tableName) /*: void*/
3387+
private function setComponentSchema(String $tableName) /*: void*/
33883388
{
3389-
$this->openapi->set("$prefix|$tableName|type", "object");
3389+
$this->openapi->set("components|schemas|$tableName|type", "object");
33903390
$table = $this->reflection->getTable($tableName);
33913391
foreach ($table->columnNames() as $columnName) {
33923392
$column = $table->get($columnName);
3393-
$type = $this->types[$column->getType()];
3394-
$this->openapi->set("$prefix|$tableName|properties|$columnName|type", $type);
3393+
$properties = $this->types[$column->getType()];
3394+
foreach ($properties as $key => $value) {
3395+
$this->openapi->set("components|schemas|$tableName|properties|$columnName|$key", $type);
3396+
}
3397+
33953398
}
33963399
}
33973400

3398-
private function setTag(String $prefix, int $index, String $tableName) /*: void*/
3401+
private function setTag(int $index, String $tableName) /*: void*/
33993402
{
3400-
$this->openapi->set("$prefix|$index|name", "$tableName");
3401-
$this->openapi->set("$prefix|$index|description", "$tableName operations");
3403+
$this->openapi->set("tags|$index|name", "$tableName");
3404+
$this->openapi->set("tags|$index|description", "$tableName operations");
34023405
}
34033406
}
34043407

src/Tqdev/PhpCrudApi/OpenApi/OpenApiBuilder.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ class OpenApiBuilder
1717
'increment' => 'patch',
1818
];
1919
private $types = [
20-
'integer' => 'integer',
21-
'varchar' => 'string',
22-
'blob' => 'string',
23-
'clob' => 'string',
24-
'decimal' => 'string',
25-
'timestamp' => 'string',
26-
'geometry' => 'string',
27-
'boolean' => 'boolean',
20+
'integer' => ['type' => 'integer', 'format' => 'int64'],
21+
'varchar' => ['type' => 'string'],
22+
'blob' => ['type' => 'string'],
23+
'clob' => ['type' => 'string'],
24+
'decimal' => ['type' => 'string'],
25+
'timestamp' => ['type' => 'string'],
26+
'geometry' => ['type' => 'string'],
27+
'boolean' => ['type' => 'boolean'],
2828
];
2929

3030
public function __construct(ReflectionService $reflection, $base)
@@ -75,12 +75,15 @@ private function setPath(String $tableName) /*: void*/
7575

7676
private function setComponentSchema(String $tableName) /*: void*/
7777
{
78-
$this->openapi->set("$prefix|$tableName|type", "object");
78+
$this->openapi->set("components|schemas|$tableName|type", "object");
7979
$table = $this->reflection->getTable($tableName);
8080
foreach ($table->columnNames() as $columnName) {
8181
$column = $table->get($columnName);
82-
$type = $this->types[$column->getType()];
83-
$this->openapi->set("components|schemas|$tableName|properties|$columnName|type", $type);
82+
$properties = $this->types[$column->getType()];
83+
foreach ($properties as $key => $value) {
84+
$this->openapi->set("components|schemas|$tableName|properties|$columnName|$key", $type);
85+
}
86+
8487
}
8588
}
8689

0 commit comments

Comments
 (0)