mirror of https://gitee.com/karson/fastadmin.git
优化API文档生成
parent
77300998fc
commit
279d8d876f
|
|
@ -98,13 +98,19 @@ class Api extends Command
|
|||
foreach ($files as $name => $file) {
|
||||
if (!$file->isDir() && $file->getExtension() == 'php') {
|
||||
$filePath = $file->getRealPath();
|
||||
$classes[] = $this->getClassFromFile($filePath);
|
||||
$className = $this->getClassFromFile($filePath);
|
||||
if ($className) {
|
||||
$classes[] = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($controller as $index => $item) {
|
||||
$filePath = $moduleDir . Config::get('url_controller_layer') . DS . $item . '.php';
|
||||
$classes[] = $this->getClassFromFile($filePath);
|
||||
$className = $this->getClassFromFile($filePath);
|
||||
if ($className) {
|
||||
$classes[] = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +189,7 @@ class Api extends Command
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $namespace . '\\' . $class;
|
||||
$className = $namespace . '\\' . $class;
|
||||
return preg_match('/([a-z0-9_\\]+)([a-z0-9_]+)$/i', $className) ? $className : '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,14 +90,15 @@ class Builder
|
|||
|
||||
$typeArr = [
|
||||
'integer' => 'number',
|
||||
'file' => 'file',
|
||||
'file' => 'file',
|
||||
];
|
||||
$paramslist = array();
|
||||
foreach ($docs['ApiParams'] as $params) {
|
||||
$inputtype = $params['type'] && isset($typeArr[$params['type']]) ? $typeArr[$params['type']] : ($params['name'] == 'password' ? 'password' : 'text');
|
||||
$type = strtolower($params['type'] ?? 'string');
|
||||
$inputtype = $typeArr[$type] ?? ($params['name'] == 'password' ? 'password' : 'text');
|
||||
$tr = array(
|
||||
'name' => $params['name'],
|
||||
'type' => $params['type'] ?? 'string',
|
||||
'type' => $type,
|
||||
'inputtype' => $inputtype,
|
||||
'sample' => $params['sample'] ?? '',
|
||||
'required' => $params['required'] ?? true,
|
||||
|
|
@ -162,7 +163,7 @@ class Builder
|
|||
'OPTIONS' => 'label-info'
|
||||
);
|
||||
|
||||
return isset($labes[$method]) ? $labes[$method] : $labes['GET'];
|
||||
return $labes[$method] ?? $labes['GET'];
|
||||
}
|
||||
|
||||
public function parse()
|
||||
|
|
@ -230,7 +231,7 @@ class Builder
|
|||
foreach ($docsList as $index => &$methods) {
|
||||
$methodSectorArr = [];
|
||||
foreach ($methods as $name => $method) {
|
||||
$methodSectorArr[$name] = isset($method['weigh']) ? $method['weigh'] : 0;
|
||||
$methodSectorArr[$name] = $method['weigh'] ?? 0;
|
||||
}
|
||||
arsort($methodSectorArr);
|
||||
$methods = array_merge(array_flip(array_keys($methodSectorArr)), $methods);
|
||||
|
|
@ -253,7 +254,6 @@ class Builder
|
|||
public function render($template, $vars = [])
|
||||
{
|
||||
$docsList = $this->parse();
|
||||
|
||||
return $this->view->display(file_get_contents($template), array_merge($vars, ['docsList' => $docsList]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,8 +154,8 @@
|
|||
<div id="sidebar">
|
||||
<div class="list-group panel">
|
||||
{foreach name="docsList" id="docs"}
|
||||
<a href="#{$key}" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">{$key} <i class="fa fa-caret-down"></i></a>
|
||||
<div class="child collapse" id="{$key}">
|
||||
<a href="#{$key|md5|substr=0,8}" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">{$key} <i class="fa fa-caret-down"></i></a>
|
||||
<div class="child collapse" id="{$key|md5|substr=0,8}">
|
||||
{foreach name="docs" id="api" }
|
||||
<a href="javascript:;" data-id="{$api.id}" class="list-group-item">{$api.title}
|
||||
<span class="tag">
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class Common extends Api
|
|||
/**
|
||||
* 上传文件
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="file", type="File", required=true, description="文件流")
|
||||
* @ApiParams (name="file", type="file", required=true, description="文件流")
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue