@@ -36,6 +36,11 @@ class OpenApiRecordsBuilder
36
36
'boolean ' => ['type ' => 'boolean ' ],
37
37
];
38
38
39
+ private function normalize (string $ value ): string
40
+ {
41
+ return iconv ('UTF-8 ' , 'ASCII//TRANSLIT ' , $ value );
42
+ }
43
+
39
44
public function __construct (OpenApiDefinition $ openapi , ReflectionService $ reflection )
40
45
{
41
46
$ this ->openapi = $ openapi ;
@@ -109,6 +114,7 @@ private function isOperationOnColumnAllowed(string $operation, string $tableName
109
114
110
115
private function setPath (string $ tableName ) /*: void*/
111
116
{
117
+ $ normalizedTableName = $ this ->normalize ($ tableName );
112
118
$ table = $ this ->reflection ->getTable ($ tableName );
113
119
$ type = $ table ->getType ();
114
120
$ pk = $ table ->getPk ();
@@ -141,14 +147,14 @@ private function setPath(string $tableName) /*: void*/
141
147
$ this ->openapi ->set ("paths| $ path| $ method|parameters| $ p| \$ref " , "#/components/parameters/ $ parameter " );
142
148
}
143
149
if (in_array ($ operation , ['create ' , 'update ' , 'increment ' ])) {
144
- $ this ->openapi ->set ("paths| $ path| $ method|requestBody| \$ref " , "#/components/requestBodies/ $ operation- " . rawurlencode ( $ tableName ) );
150
+ $ this ->openapi ->set ("paths| $ path| $ method|requestBody| \$ref " , "#/components/requestBodies/ $ operation- $ normalizedTableName " );
145
151
}
146
152
$ this ->openapi ->set ("paths| $ path| $ method|tags|0 " , "$ tableName " );
147
- $ this ->openapi ->set ("paths| $ path| $ method|operationId " , "$ operation " . "_ " . "$ tableName " );
153
+ $ this ->openapi ->set ("paths| $ path| $ method|operationId " , "$ operation " . "_ " . "$ normalizedTableName " );
148
154
$ this ->openapi ->set ("paths| $ path| $ method|description " , "$ operation $ tableName " );
149
155
switch ($ operation ) {
150
156
case 'list ' :
151
- $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/ $ operation- " . rawurlencode ( $ tableName ) );
157
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/ $ operation- $ normalizedTableName " );
152
158
break ;
153
159
case 'create ' :
154
160
if ($ pk ->getType () == 'integer ' ) {
@@ -158,7 +164,7 @@ private function setPath(string $tableName) /*: void*/
158
164
}
159
165
break ;
160
166
case 'read ' :
161
- $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/ $ operation- " . rawurlencode ( $ tableName ) );
167
+ $ this ->openapi ->set ("paths| $ path| $ method|responses|200| \$ref " , "#/components/responses/ $ operation- $ normalizedTableName " );
162
168
break ;
163
169
case 'update ' :
164
170
case 'delete ' :
@@ -214,6 +220,7 @@ private function getPattern(ReflectedColumn $column): string
214
220
215
221
private function setComponentSchema (string $ tableName , array $ references ) /*: void*/
216
222
{
223
+ $ normalizedTableName = $ this ->normalize ($ tableName );
217
224
$ table = $ this ->reflection ->getTable ($ tableName );
218
225
$ type = $ table ->getType ();
219
226
$ pk = $ table ->getPk ();
@@ -235,13 +242,13 @@ private function setComponentSchema(string $tableName, array $references) /*: vo
235
242
continue ;
236
243
}
237
244
if ($ operation == 'list ' ) {
238
- $ this ->openapi ->set ("components|schemas| $ operation- $ tableName |type " , "object " );
239
- $ this ->openapi ->set ("components|schemas| $ operation- $ tableName |properties|results|type " , "integer " );
240
- $ this ->openapi ->set ("components|schemas| $ operation- $ tableName |properties|results|format " , "int64 " );
241
- $ this ->openapi ->set ("components|schemas| $ operation- $ tableName |properties|records|type " , "array " );
242
- $ prefix = "components|schemas| $ operation- $ tableName |properties|records|items " ;
245
+ $ this ->openapi ->set ("components|schemas| $ operation- $ normalizedTableName |type " , "object " );
246
+ $ this ->openapi ->set ("components|schemas| $ operation- $ normalizedTableName |properties|results|type " , "integer " );
247
+ $ this ->openapi ->set ("components|schemas| $ operation- $ normalizedTableName |properties|results|format " , "int64 " );
248
+ $ this ->openapi ->set ("components|schemas| $ operation- $ normalizedTableName |properties|records|type " , "array " );
249
+ $ prefix = "components|schemas| $ operation- $ normalizedTableName |properties|records|items " ;
243
250
} else {
244
- $ prefix = "components|schemas| $ operation- $ tableName " ;
251
+ $ prefix = "components|schemas| $ operation- $ normalizedTableName " ;
245
252
}
246
253
$ this ->openapi ->set ("$ prefix|type " , "object " );
247
254
foreach ($ table ->getColumnNames () as $ columnName ) {
@@ -272,6 +279,7 @@ private function setComponentSchema(string $tableName, array $references) /*: vo
272
279
273
280
private function setComponentResponse (string $ tableName ) /*: void*/
274
281
{
282
+ $ normalizedTableName = $ this ->normalize ($ tableName );
275
283
$ table = $ this ->reflection ->getTable ($ tableName );
276
284
$ type = $ table ->getType ();
277
285
$ pk = $ table ->getPk ();
@@ -287,16 +295,17 @@ private function setComponentResponse(string $tableName) /*: void*/
287
295
continue ;
288
296
}
289
297
if ($ operation == 'list ' ) {
290
- $ this ->openapi ->set ("components|responses| $ operation- $ tableName |description " , "list of $ tableName records " );
298
+ $ this ->openapi ->set ("components|responses| $ operation- $ normalizedTableName |description " , "list of $ tableName records " );
291
299
} else {
292
- $ this ->openapi ->set ("components|responses| $ operation- $ tableName |description " , "single $ tableName record " );
300
+ $ this ->openapi ->set ("components|responses| $ operation- $ normalizedTableName |description " , "single $ tableName record " );
293
301
}
294
- $ this ->openapi ->set ("components|responses| $ operation- $ tableName |content|application/json|schema| \$ref " , "#/components/schemas/ $ operation- " . rawurlencode ( $ tableName ) );
302
+ $ this ->openapi ->set ("components|responses| $ operation- $ normalizedTableName |content|application/json|schema| \$ref " , "#/components/schemas/ $ operation- $ normalizedTableName " );
295
303
}
296
304
}
297
305
298
306
private function setComponentRequestBody (string $ tableName ) /*: void*/
299
307
{
308
+ $ normalizedTableName = $ this ->normalize ($ tableName );
300
309
$ table = $ this ->reflection ->getTable ($ tableName );
301
310
$ type = $ table ->getType ();
302
311
$ pk = $ table ->getPk ();
@@ -306,8 +315,8 @@ private function setComponentRequestBody(string $tableName) /*: void*/
306
315
if (!$ this ->isOperationOnTableAllowed ($ operation , $ tableName )) {
307
316
continue ;
308
317
}
309
- $ this ->openapi ->set ("components|requestBodies| $ operation- $ tableName |description " , "single $ tableName record " );
310
- $ this ->openapi ->set ("components|requestBodies| $ operation- $ tableName |content|application/json|schema| \$ref " , "#/components/schemas/ $ operation- " . rawurlencode ( $ tableName ) );
318
+ $ this ->openapi ->set ("components|requestBodies| $ operation- $ normalizedTableName |description " , "single $ tableName record " );
319
+ $ this ->openapi ->set ("components|requestBodies| $ operation- $ normalizedTableName |content|application/json|schema| \$ref " , "#/components/schemas/ $ operation- $ normalizedTableName " );
311
320
}
312
321
}
313
322
}
0 commit comments