Skip to content

Commit 32c6511

Browse files
author
Mz
committed
feat: 【site】生成swagger.json
https://e.gitee.com/liweijia/dashboard?issue=I6UGPB 支持unit.name 翻译respons中的字段
1 parent bd1f685 commit 32c6511

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/Mpociot/ApiDoc/Generators/LaravelGenerator.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ protected function getSwaggerTransformerResponse($tags)
330330
if (empty($tables)) {
331331
// $tables = \DB::getDoctrineSchemaManager()->listTableNames();
332332
}
333-
$this->addComment($datas, $tables, $columnComments, $returnData);
333+
$this->addComment($datas, $tables, $columnComments, null, $returnData);
334334
return \response(json_encode($returnData));
335335
} catch (\Exception $e) {
336336
\Log::info('LaravelGenerator::getSwaggerTransformerResponse::', [$e->getMessage()]);
@@ -353,11 +353,18 @@ private function getColumns($tables)
353353

354354
protected function getComment(array $tables, array $columnComments, string $field)
355355
{
356-
$comment = null;
357356
if (isset($columnComments[$field]) && $columnComments[$field]) {
358357
return $columnComments[$field];
358+
} else {
359+
$arrField = explode('.', $field);
360+
$name = $arrField[1] ?? null;
361+
if ($name && !is_numeric($name) && isset($columnComments[$name]) && $columnComments[$name]) {
362+
return $columnComments[$name];
363+
}
364+
return null;
359365
}
360366

367+
return null;
361368
$columns = $this->getColumns($tables);
362369
foreach ($columns as $column) {
363370
if (isset($columnComments[$field]) && $columnComments[$field]) {
@@ -373,19 +380,23 @@ protected function getComment(array $tables, array $columnComments, string $fiel
373380
return $comment;
374381
}
375382

376-
private function addComment($datas, $tables, $columnComments, &$returnData)
383+
private function addComment($datas, $tables, $columnComments, $parentKey = null, &$returnData)
377384
{
378385
foreach ($datas as $key => $data) {
386+
$newKey = $key;
387+
if ($parentKey) {
388+
$newKey = $parentKey . '.' . $key;
389+
}
390+
379391
if (in_array(gettype($data), ['object', 'array'])) {
380-
$this->addComment($data, $tables, $columnComments, $returnData[$key]);
381-
$returnData[$key]['_____description'] = $this->getComment($tables, $columnComments, $key);
392+
$this->addComment($data, $tables, $columnComments, $key, $returnData[$key]);
393+
$returnData[$key]['_____description'] = $this->getComment($tables, $columnComments, $newKey);
382394
} else {
383-
384395
$returnData[$key] = [
385396
'_____key' => Uuid::uuid4()->toString(),
386397
'value' => $data,
387398
'type' => gettype($data),
388-
'description' => $this->getComment($tables, $columnComments, $key),
399+
'description' => $this->getComment($tables, $columnComments, $newKey),
389400
];
390401
}
391402
}

0 commit comments

Comments
 (0)