作者 lackoxygen

feat

... ... @@ -3,19 +3,20 @@
namespace Lackoxygen\ShowDocGeneration\Annotations;
use Doctrine\Common\Annotations\Annotation\Required;
use Lackoxygen\ShowDocGeneration\Contracts\JsonPasterInterface;
/**
* @Annotation
* @Target({"METHOD"})
* @Attributes({
@Attribute("value", type = "string"),
@Attribute("resource", type = "string"),
* })
*/
final class Resp extends Annotation
final class RespResource extends Annotation
{
/**
* @Required()
* @var string
*/
protected string $value = '{}';
protected string $resource = '';
}
... ...
... ... @@ -2,6 +2,7 @@
namespace Lackoxygen\ShowDocGeneration\Writer;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Lackoxygen\ShowDocGeneration\Annotations\Method;
use Lackoxygen\ShowDocGeneration\Parser\Doc;
... ... @@ -51,7 +52,7 @@ t;
protected string $output = '';
public function __construct(Doc $doc)
public function __construct(Doc $doc, string $resourcePath)
{
$editTemplate = $this->template;
... ... @@ -61,12 +62,30 @@ t;
'method' => Arr::get($doc->method, 'method', Method::METHOD_GET),
'headers' => join("\n", $this->tableTbody($doc->headerLine)),
'params' => join("\n", $this->tableTbody($doc->paramLine)),
'resp' => Arr::get($doc->resp, 'value', '{}'),
'resp' => '{}',
'respRemark' => join("\n", $this->tableTbody($doc->respLine)),
'middles' => join("\n", $this->unorderedList($doc->middles)),
'updateTime' => now()->toString()
];
$respResource = Arr::get($doc->respResource, 'resource');
if ($respResource) {
$resourceInfo = pathinfo($respResource);
if (!isset($resourceInfo['extension'])) {
$respResource .= '.json';
}
$resourceFile = rtrim($resourcePath, '/\\') . DIRECTORY_SEPARATOR . $respResource;
$fs = new Filesystem();
if ($fs->exists($resourceFile) && $respData = $fs->sharedGet($resourceFile)) {
Arr::set($replaces, 'resp', $respData);
}
}
$this->output = \str_replace(
\array_map(function (string $key) {
return '{{' . $key . '}}';
... ...