Skip to content

Commit abea028

Browse files
committed
Improve parameters
1 parent ad9b1c5 commit abea028

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

api.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3359,6 +3359,7 @@ public function build(): OpenApiDefinition
33593359
foreach ($tableNames as $tableName) {
33603360
$this->setComponentSchema($tableName);
33613361
}
3362+
$this->setComponentParameters();
33623363
foreach ($tableNames as $index => $tableName) {
33633364
$this->setTag($index, $tableName);
33643365
}
@@ -3378,10 +3379,7 @@ private function setPath(String $tableName) /*: void*/
33783379
continue;
33793380
}
33803381
$path = sprintf('/records/%s/{%s}', $tableName, $pkName);
3381-
$this->openapi->set("paths|$path|$method|parameters|0|name", "id");
3382-
$this->openapi->set("paths|$path|$method|parameters|0|in", "path");
3383-
$this->openapi->set("paths|$path|$method|parameters|0|schema|type", "string");
3384-
$this->openapi->set("paths|$path|$method|parameters|0|required", true);
3382+
$this->openapi->set("paths|$path|$method|parameters|0|\$ref", "#/components/parameters/pk");
33853383
}
33863384
$this->openapi->set("paths|$path|$method|tags|0", "$tableName");
33873385
$this->openapi->set("paths|$path|$method|description", "$operation $tableName");
@@ -3403,6 +3401,15 @@ private function setComponentSchema(String $tableName) /*: void*/
34033401
}
34043402
}
34053403

3404+
private function setComponentParameters() /*: void*/
3405+
{
3406+
$this->openapi->set("components|parameters|pk|name", "id");
3407+
$this->openapi->set("components|parameters|pk|in", "path");
3408+
$this->openapi->set("components|parameters|pk|schema|type", "string");
3409+
$this->openapi->set("components|parameters|pk|description", "primary key value");
3410+
$this->openapi->set("components|parameters|pk|required", true);
3411+
}
3412+
34063413
private function setTag(int $index, String $tableName) /*: void*/
34073414
{
34083415
$this->openapi->set("tags|$index|name", "$tableName");

src/Tqdev/PhpCrudApi/OpenApi/OpenApiBuilder.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function build(): OpenApiDefinition
4848
foreach ($tableNames as $tableName) {
4949
$this->setComponentSchema($tableName);
5050
}
51+
$this->setComponentParameters();
5152
foreach ($tableNames as $index => $tableName) {
5253
$this->setTag($index, $tableName);
5354
}
@@ -67,10 +68,7 @@ private function setPath(String $tableName) /*: void*/
6768
continue;
6869
}
6970
$path = sprintf('/records/%s/{%s}', $tableName, $pkName);
70-
$this->openapi->set("paths|$path|$method|parameters|0|name", "id");
71-
$this->openapi->set("paths|$path|$method|parameters|0|in", "path");
72-
$this->openapi->set("paths|$path|$method|parameters|0|schema|type", "string");
73-
$this->openapi->set("paths|$path|$method|parameters|0|required", true);
71+
$this->openapi->set("paths|$path|$method|parameters|0|\$ref", "#/components/parameters/pk");
7472
}
7573
$this->openapi->set("paths|$path|$method|tags|0", "$tableName");
7674
$this->openapi->set("paths|$path|$method|description", "$operation $tableName");
@@ -92,6 +90,15 @@ private function setComponentSchema(String $tableName) /*: void*/
9290
}
9391
}
9492

93+
private function setComponentParameters() /*: void*/
94+
{
95+
$this->openapi->set("components|parameters|pk|name", "id");
96+
$this->openapi->set("components|parameters|pk|in", "path");
97+
$this->openapi->set("components|parameters|pk|schema|type", "string");
98+
$this->openapi->set("components|parameters|pk|description", "primary key value");
99+
$this->openapi->set("components|parameters|pk|required", true);
100+
}
101+
95102
private function setTag(int $index, String $tableName) /*: void*/
96103
{
97104
$this->openapi->set("tags|$index|name", "$tableName");

0 commit comments

Comments
 (0)