|
@@ -2,6 +2,7 @@ |
|
@@ -2,6 +2,7 @@ |
|
2
|
|
2
|
|
|
3
|
namespace Lackoxygen\ShowDocGeneration\Writer;
|
3
|
namespace Lackoxygen\ShowDocGeneration\Writer;
|
|
4
|
|
4
|
|
|
|
|
5
|
+use Illuminate\Filesystem\Filesystem;
|
|
5
|
use Illuminate\Support\Arr;
|
6
|
use Illuminate\Support\Arr;
|
|
6
|
use Lackoxygen\ShowDocGeneration\Annotations\Method;
|
7
|
use Lackoxygen\ShowDocGeneration\Annotations\Method;
|
|
7
|
use Lackoxygen\ShowDocGeneration\Parser\Doc;
|
8
|
use Lackoxygen\ShowDocGeneration\Parser\Doc;
|
|
@@ -51,7 +52,7 @@ t; |
|
@@ -51,7 +52,7 @@ t; |
|
51
|
|
52
|
|
|
52
|
protected string $output = '';
|
53
|
protected string $output = '';
|
|
53
|
|
54
|
|
|
54
|
- public function __construct(Doc $doc)
|
55
|
+ public function __construct(Doc $doc, string $resourcePath)
|
|
55
|
{
|
56
|
{
|
|
56
|
$editTemplate = $this->template;
|
57
|
$editTemplate = $this->template;
|
|
57
|
|
58
|
|
|
@@ -61,12 +62,30 @@ t; |
|
@@ -61,12 +62,30 @@ t; |
|
61
|
'method' => Arr::get($doc->method, 'method', Method::METHOD_GET),
|
62
|
'method' => Arr::get($doc->method, 'method', Method::METHOD_GET),
|
|
62
|
'headers' => join("\n", $this->tableTbody($doc->headerLine)),
|
63
|
'headers' => join("\n", $this->tableTbody($doc->headerLine)),
|
|
63
|
'params' => join("\n", $this->tableTbody($doc->paramLine)),
|
64
|
'params' => join("\n", $this->tableTbody($doc->paramLine)),
|
|
64
|
- 'resp' => Arr::get($doc->resp, 'value', '{}'),
|
65
|
+ 'resp' => '{}',
|
|
65
|
'respRemark' => join("\n", $this->tableTbody($doc->respLine)),
|
66
|
'respRemark' => join("\n", $this->tableTbody($doc->respLine)),
|
|
66
|
'middles' => join("\n", $this->unorderedList($doc->middles)),
|
67
|
'middles' => join("\n", $this->unorderedList($doc->middles)),
|
|
67
|
'updateTime' => now()->toString()
|
68
|
'updateTime' => now()->toString()
|
|
68
|
];
|
69
|
];
|
|
69
|
|
70
|
|
|
|
|
71
|
+ $respResource = Arr::get($doc->respResource, 'resource');
|
|
|
|
72
|
+
|
|
|
|
73
|
+ if ($respResource) {
|
|
|
|
74
|
+ $resourceInfo = pathinfo($respResource);
|
|
|
|
75
|
+
|
|
|
|
76
|
+ if (!isset($resourceInfo['extension'])) {
|
|
|
|
77
|
+ $respResource .= '.json';
|
|
|
|
78
|
+ }
|
|
|
|
79
|
+
|
|
|
|
80
|
+ $resourceFile = rtrim($resourcePath, '/\\') . DIRECTORY_SEPARATOR . $respResource;
|
|
|
|
81
|
+
|
|
|
|
82
|
+ $fs = new Filesystem();
|
|
|
|
83
|
+
|
|
|
|
84
|
+ if ($fs->exists($resourceFile) && $respData = $fs->sharedGet($resourceFile)) {
|
|
|
|
85
|
+ Arr::set($replaces, 'resp', $respData);
|
|
|
|
86
|
+ }
|
|
|
|
87
|
+ }
|
|
|
|
88
|
+
|
|
70
|
$this->output = \str_replace(
|
89
|
$this->output = \str_replace(
|
|
71
|
\array_map(function (string $key) {
|
90
|
\array_map(function (string $key) {
|
|
72
|
return '{{' . $key . '}}';
|
91
|
return '{{' . $key . '}}';
|