Skip to content

Commit df5fa88

Browse files
committed
utf8 in component ids
1 parent 27f37b2 commit df5fa88

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

api.include.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9337,6 +9337,11 @@ class OpenApiRecordsBuilder
93379337
'boolean' => ['type' => 'boolean'],
93389338
];
93399339

9340+
private function normalize(string $value): string
9341+
{
9342+
return iconv('UTF-8', 'ASCII//TRANSLIT', $value);
9343+
}
9344+
93409345
public function __construct(OpenApiDefinition $openapi, ReflectionService $reflection)
93419346
{
93429347
$this->openapi = $openapi;
@@ -9410,6 +9415,7 @@ private function isOperationOnColumnAllowed(string $operation, string $tableName
94109415

94119416
private function setPath(string $tableName) /*: void*/
94129417
{
9418+
$normalizedTableName = $this->normalize($tableName);
94139419
$table = $this->reflection->getTable($tableName);
94149420
$type = $table->getType();
94159421
$pk = $table->getPk();
@@ -9442,14 +9448,14 @@ private function setPath(string $tableName) /*: void*/
94429448
$this->openapi->set("paths|$path|$method|parameters|$p|\$ref", "#/components/parameters/$parameter");
94439449
}
94449450
if (in_array($operation, ['create', 'update', 'increment'])) {
9445-
$this->openapi->set("paths|$path|$method|requestBody|\$ref", "#/components/requestBodies/$operation-" . rawurlencode($tableName));
9451+
$this->openapi->set("paths|$path|$method|requestBody|\$ref", "#/components/requestBodies/$operation-$normalizedTableName");
94469452
}
94479453
$this->openapi->set("paths|$path|$method|tags|0", "$tableName");
9448-
$this->openapi->set("paths|$path|$method|operationId", "$operation" . "_" . "$tableName");
9454+
$this->openapi->set("paths|$path|$method|operationId", "$operation" . "_" . "$normalizedTableName");
94499455
$this->openapi->set("paths|$path|$method|description", "$operation $tableName");
94509456
switch ($operation) {
94519457
case 'list':
9452-
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operation-" . rawurlencode($tableName));
9458+
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operation-$normalizedTableName");
94539459
break;
94549460
case 'create':
94559461
if ($pk->getType() == 'integer') {
@@ -9459,7 +9465,7 @@ private function setPath(string $tableName) /*: void*/
94599465
}
94609466
break;
94619467
case 'read':
9462-
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operation-" . rawurlencode($tableName));
9468+
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operation-$normalizedTableName");
94639469
break;
94649470
case 'update':
94659471
case 'delete':
@@ -9515,6 +9521,7 @@ private function getPattern(ReflectedColumn $column): string
95159521

95169522
private function setComponentSchema(string $tableName, array $references) /*: void*/
95179523
{
9524+
$normalizedTableName = $this->normalize($tableName);
95189525
$table = $this->reflection->getTable($tableName);
95199526
$type = $table->getType();
95209527
$pk = $table->getPk();
@@ -9536,13 +9543,13 @@ private function setComponentSchema(string $tableName, array $references) /*: vo
95369543
continue;
95379544
}
95389545
if ($operation == 'list') {
9539-
$this->openapi->set("components|schemas|$operation-$tableName|type", "object");
9540-
$this->openapi->set("components|schemas|$operation-$tableName|properties|results|type", "integer");
9541-
$this->openapi->set("components|schemas|$operation-$tableName|properties|results|format", "int64");
9542-
$this->openapi->set("components|schemas|$operation-$tableName|properties|records|type", "array");
9543-
$prefix = "components|schemas|$operation-$tableName|properties|records|items";
9546+
$this->openapi->set("components|schemas|$operation-$normalizedTableName|type", "object");
9547+
$this->openapi->set("components|schemas|$operation-$normalizedTableName|properties|results|type", "integer");
9548+
$this->openapi->set("components|schemas|$operation-$normalizedTableName|properties|results|format", "int64");
9549+
$this->openapi->set("components|schemas|$operation-$normalizedTableName|properties|records|type", "array");
9550+
$prefix = "components|schemas|$operation-$normalizedTableName|properties|records|items";
95449551
} else {
9545-
$prefix = "components|schemas|$operation-$tableName";
9552+
$prefix = "components|schemas|$operation-$normalizedTableName";
95469553
}
95479554
$this->openapi->set("$prefix|type", "object");
95489555
foreach ($table->getColumnNames() as $columnName) {
@@ -9573,6 +9580,7 @@ private function setComponentSchema(string $tableName, array $references) /*: vo
95739580

95749581
private function setComponentResponse(string $tableName) /*: void*/
95759582
{
9583+
$normalizedTableName = $this->normalize($tableName);
95769584
$table = $this->reflection->getTable($tableName);
95779585
$type = $table->getType();
95789586
$pk = $table->getPk();
@@ -9588,16 +9596,17 @@ private function setComponentResponse(string $tableName) /*: void*/
95889596
continue;
95899597
}
95909598
if ($operation == 'list') {
9591-
$this->openapi->set("components|responses|$operation-$tableName|description", "list of $tableName records");
9599+
$this->openapi->set("components|responses|$operation-$normalizedTableName|description", "list of $tableName records");
95929600
} else {
9593-
$this->openapi->set("components|responses|$operation-$tableName|description", "single $tableName record");
9601+
$this->openapi->set("components|responses|$operation-$normalizedTableName|description", "single $tableName record");
95949602
}
9595-
$this->openapi->set("components|responses|$operation-$tableName|content|application/json|schema|\$ref", "#/components/schemas/$operation-" . rawurlencode($tableName));
9603+
$this->openapi->set("components|responses|$operation-$normalizedTableName|content|application/json|schema|\$ref", "#/components/schemas/$operation-$normalizedTableName");
95969604
}
95979605
}
95989606

95999607
private function setComponentRequestBody(string $tableName) /*: void*/
96009608
{
9609+
$normalizedTableName = $this->normalize($tableName);
96019610
$table = $this->reflection->getTable($tableName);
96029611
$type = $table->getType();
96039612
$pk = $table->getPk();
@@ -9607,8 +9616,8 @@ private function setComponentRequestBody(string $tableName) /*: void*/
96079616
if (!$this->isOperationOnTableAllowed($operation, $tableName)) {
96089617
continue;
96099618
}
9610-
$this->openapi->set("components|requestBodies|$operation-$tableName|description", "single $tableName record");
9611-
$this->openapi->set("components|requestBodies|$operation-$tableName|content|application/json|schema|\$ref", "#/components/schemas/$operation-" . rawurlencode($tableName));
9619+
$this->openapi->set("components|requestBodies|$operation-$normalizedTableName|description", "single $tableName record");
9620+
$this->openapi->set("components|requestBodies|$operation-$normalizedTableName|content|application/json|schema|\$ref", "#/components/schemas/$operation-$normalizedTableName");
96129621
}
96139622
}
96149623
}

api.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9337,6 +9337,11 @@ class OpenApiRecordsBuilder
93379337
'boolean' => ['type' => 'boolean'],
93389338
];
93399339

9340+
private function normalize(string $value): string
9341+
{
9342+
return iconv('UTF-8', 'ASCII//TRANSLIT', $value);
9343+
}
9344+
93409345
public function __construct(OpenApiDefinition $openapi, ReflectionService $reflection)
93419346
{
93429347
$this->openapi = $openapi;
@@ -9410,6 +9415,7 @@ private function isOperationOnColumnAllowed(string $operation, string $tableName
94109415

94119416
private function setPath(string $tableName) /*: void*/
94129417
{
9418+
$normalizedTableName = $this->normalize($tableName);
94139419
$table = $this->reflection->getTable($tableName);
94149420
$type = $table->getType();
94159421
$pk = $table->getPk();
@@ -9442,14 +9448,14 @@ private function setPath(string $tableName) /*: void*/
94429448
$this->openapi->set("paths|$path|$method|parameters|$p|\$ref", "#/components/parameters/$parameter");
94439449
}
94449450
if (in_array($operation, ['create', 'update', 'increment'])) {
9445-
$this->openapi->set("paths|$path|$method|requestBody|\$ref", "#/components/requestBodies/$operation-" . rawurlencode($tableName));
9451+
$this->openapi->set("paths|$path|$method|requestBody|\$ref", "#/components/requestBodies/$operation-$normalizedTableName");
94469452
}
94479453
$this->openapi->set("paths|$path|$method|tags|0", "$tableName");
9448-
$this->openapi->set("paths|$path|$method|operationId", "$operation" . "_" . "$tableName");
9454+
$this->openapi->set("paths|$path|$method|operationId", "$operation" . "_" . "$normalizedTableName");
94499455
$this->openapi->set("paths|$path|$method|description", "$operation $tableName");
94509456
switch ($operation) {
94519457
case 'list':
9452-
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operation-" . rawurlencode($tableName));
9458+
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operation-$normalizedTableName");
94539459
break;
94549460
case 'create':
94559461
if ($pk->getType() == 'integer') {
@@ -9459,7 +9465,7 @@ private function setPath(string $tableName) /*: void*/
94599465
}
94609466
break;
94619467
case 'read':
9462-
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operation-" . rawurlencode($tableName));
9468+
$this->openapi->set("paths|$path|$method|responses|200|\$ref", "#/components/responses/$operation-$normalizedTableName");
94639469
break;
94649470
case 'update':
94659471
case 'delete':
@@ -9515,6 +9521,7 @@ private function getPattern(ReflectedColumn $column): string
95159521

95169522
private function setComponentSchema(string $tableName, array $references) /*: void*/
95179523
{
9524+
$normalizedTableName = $this->normalize($tableName);
95189525
$table = $this->reflection->getTable($tableName);
95199526
$type = $table->getType();
95209527
$pk = $table->getPk();
@@ -9536,13 +9543,13 @@ private function setComponentSchema(string $tableName, array $references) /*: vo
95369543
continue;
95379544
}
95389545
if ($operation == 'list') {
9539-
$this->openapi->set("components|schemas|$operation-$tableName|type", "object");
9540-
$this->openapi->set("components|schemas|$operation-$tableName|properties|results|type", "integer");
9541-
$this->openapi->set("components|schemas|$operation-$tableName|properties|results|format", "int64");
9542-
$this->openapi->set("components|schemas|$operation-$tableName|properties|records|type", "array");
9543-
$prefix = "components|schemas|$operation-$tableName|properties|records|items";
9546+
$this->openapi->set("components|schemas|$operation-$normalizedTableName|type", "object");
9547+
$this->openapi->set("components|schemas|$operation-$normalizedTableName|properties|results|type", "integer");
9548+
$this->openapi->set("components|schemas|$operation-$normalizedTableName|properties|results|format", "int64");
9549+
$this->openapi->set("components|schemas|$operation-$normalizedTableName|properties|records|type", "array");
9550+
$prefix = "components|schemas|$operation-$normalizedTableName|properties|records|items";
95449551
} else {
9545-
$prefix = "components|schemas|$operation-$tableName";
9552+
$prefix = "components|schemas|$operation-$normalizedTableName";
95469553
}
95479554
$this->openapi->set("$prefix|type", "object");
95489555
foreach ($table->getColumnNames() as $columnName) {
@@ -9573,6 +9580,7 @@ private function setComponentSchema(string $tableName, array $references) /*: vo
95739580

95749581
private function setComponentResponse(string $tableName) /*: void*/
95759582
{
9583+
$normalizedTableName = $this->normalize($tableName);
95769584
$table = $this->reflection->getTable($tableName);
95779585
$type = $table->getType();
95789586
$pk = $table->getPk();
@@ -9588,16 +9596,17 @@ private function setComponentResponse(string $tableName) /*: void*/
95889596
continue;
95899597
}
95909598
if ($operation == 'list') {
9591-
$this->openapi->set("components|responses|$operation-$tableName|description", "list of $tableName records");
9599+
$this->openapi->set("components|responses|$operation-$normalizedTableName|description", "list of $tableName records");
95929600
} else {
9593-
$this->openapi->set("components|responses|$operation-$tableName|description", "single $tableName record");
9601+
$this->openapi->set("components|responses|$operation-$normalizedTableName|description", "single $tableName record");
95949602
}
9595-
$this->openapi->set("components|responses|$operation-$tableName|content|application/json|schema|\$ref", "#/components/schemas/$operation-" . rawurlencode($tableName));
9603+
$this->openapi->set("components|responses|$operation-$normalizedTableName|content|application/json|schema|\$ref", "#/components/schemas/$operation-$normalizedTableName");
95969604
}
95979605
}
95989606

95999607
private function setComponentRequestBody(string $tableName) /*: void*/
96009608
{
9609+
$normalizedTableName = $this->normalize($tableName);
96019610
$table = $this->reflection->getTable($tableName);
96029611
$type = $table->getType();
96039612
$pk = $table->getPk();
@@ -9607,8 +9616,8 @@ private function setComponentRequestBody(string $tableName) /*: void*/
96079616
if (!$this->isOperationOnTableAllowed($operation, $tableName)) {
96089617
continue;
96099618
}
9610-
$this->openapi->set("components|requestBodies|$operation-$tableName|description", "single $tableName record");
9611-
$this->openapi->set("components|requestBodies|$operation-$tableName|content|application/json|schema|\$ref", "#/components/schemas/$operation-" . rawurlencode($tableName));
9619+
$this->openapi->set("components|requestBodies|$operation-$normalizedTableName|description", "single $tableName record");
9620+
$this->openapi->set("components|requestBodies|$operation-$normalizedTableName|content|application/json|schema|\$ref", "#/components/schemas/$operation-$normalizedTableName");
96129621
}
96139622
}
96149623
}

0 commit comments

Comments
 (0)