mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 完成接口文档自动生成
This commit is contained in:
parent
36c8e22dda
commit
2762eb8484
@ -44,7 +44,7 @@ return [
|
|||||||
'wiki/index/errorCode',
|
'wiki/index/errorCode',
|
||||||
['method' => 'get']
|
['method' => 'get']
|
||||||
],
|
],
|
||||||
'detail/:hash' => [
|
'detail/:groupHash/[:hash]' => [
|
||||||
'wiki/index/detail',
|
'wiki/index/detail',
|
||||||
['method' => 'get']
|
['method' => 'get']
|
||||||
],
|
],
|
||||||
@ -52,6 +52,6 @@ return [
|
|||||||
'wiki/index/logout',
|
'wiki/index/logout',
|
||||||
['method' => 'get']
|
['method' => 'get']
|
||||||
],
|
],
|
||||||
'__miss__' => ['api/Miss/index'],
|
'__miss__' => ['wiki/index/index'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
@ -41,19 +41,32 @@ class Index extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function detail() {
|
public function detail() {
|
||||||
$gid = $this->request->route('gid');
|
$this->checkLogin();
|
||||||
$hash = $this->request->route('hash');
|
|
||||||
$newList = [];
|
$groupHash = $this->request->route('groupHash');
|
||||||
$apiList = ApiList::all(['groupId' => $gid]);
|
$hash = $this->request->route('hash', '');
|
||||||
foreach ($apiList as $value) {
|
$this->appInfo['app_api_show'] = json_decode($this->appInfo['app_api_show'], true);
|
||||||
$newList[$value['hash']] = $value;
|
if (!isset($this->appInfo['app_api_show'][$groupHash]) || empty($this->appInfo['app_api_show'][$groupHash])) {
|
||||||
|
$this->error('请求非法', url('/wiki/index'));
|
||||||
}
|
}
|
||||||
if ($hash) {
|
|
||||||
$detail = $newList[$hash];
|
if (!$hash) {
|
||||||
|
$hash = $this->appInfo['app_api_show'][$groupHash][0];
|
||||||
} else {
|
} else {
|
||||||
$detail = $apiList[0];
|
if (!in_array($hash, $this->appInfo['app_api_show'][$groupHash])) {
|
||||||
$hash = $detail['hash'];
|
$this->error('请求非法', url('/wiki/index'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$apiList = (new ApiList())->whereIn('hash', $this->appInfo['app_api_show'][$groupHash])->where(['groupHash' => $groupHash])->select();
|
||||||
|
$apiList = Tools::buildArrFromObj($apiList);
|
||||||
|
$apiList = Tools::buildArrByNewKey($apiList, 'hash');
|
||||||
|
|
||||||
|
if (!$hash) {
|
||||||
|
$hash = $this->appInfo['app_api_show'][$groupHash][0];
|
||||||
|
}
|
||||||
|
$detail = $apiList[$hash];
|
||||||
|
|
||||||
$request = ApiFields::all(['hash' => $hash, 'type' => 0]);
|
$request = ApiFields::all(['hash' => $hash, 'type' => 0]);
|
||||||
$response = ApiFields::all(['hash' => $hash, 'type' => 1]);
|
$response = ApiFields::all(['hash' => $hash, 'type' => 1]);
|
||||||
$dataType = array(
|
$dataType = array(
|
||||||
@ -67,15 +80,19 @@ class Index extends Base {
|
|||||||
DataType::TYPE_OBJECT => 'Object',
|
DataType::TYPE_OBJECT => 'Object',
|
||||||
DataType::TYPE_MOBILE => 'Mobile'
|
DataType::TYPE_MOBILE => 'Mobile'
|
||||||
);
|
);
|
||||||
$this->assign('request', $request);
|
|
||||||
$this->assign('response', $response);
|
|
||||||
$this->assign('dataType', $dataType);
|
|
||||||
$this->assign('apiList', $apiList);
|
|
||||||
$this->assign('detail', $detail);
|
|
||||||
$this->assign('hash', $hash);
|
|
||||||
$this->assign('gid', $gid);
|
|
||||||
|
|
||||||
return $this->fetch();
|
$groupInfo = ApiGroup::get(['hash' => $groupHash])->toArray();
|
||||||
|
|
||||||
|
return view('', [
|
||||||
|
'groupInfo' => $groupInfo,
|
||||||
|
'request' => $request,
|
||||||
|
'response' => $response,
|
||||||
|
'dataType' => $dataType,
|
||||||
|
'apiList' => $apiList,
|
||||||
|
'detail' => $detail,
|
||||||
|
'hash' => $hash,
|
||||||
|
'groupHash' => $groupHash
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function calculation() {
|
public function calculation() {
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
<img src="http://static10.photo.sina.com.cn/middle/5a3ab1b1x9961016a8699&690">
|
<img src="http://static10.photo.sina.com.cn/middle/5a3ab1b1x9961016a8699&690">
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<span class="header">XXX分组</span>
|
<span class="header">{$groupInfo['name']}</span>
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<p>系统将严格过滤请求字段,并且进行全部必要认证! 系统将严格过滤请求字段,并且进行全部必要认证! 系统将严格过滤请求字段,并且进行全部必要认证! 系统将严格过滤请求字段,并且进行全部必要认证!</p>
|
<p>{$groupInfo['description']}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="extra">
|
<div class="extra">
|
||||||
额外的细节
|
额外的细节
|
||||||
@ -36,7 +36,7 @@
|
|||||||
<div class="four wide column">
|
<div class="four wide column">
|
||||||
<div class="ui vertical menu" style="width: 100%;overflow: auto;">
|
<div class="ui vertical menu" style="width: 100%;overflow: auto;">
|
||||||
{volist name="apiList" id="vo"}
|
{volist name="apiList" id="vo"}
|
||||||
<a class="{if condition="$hash == $vo['hash']"}active{/if} teal item" href="{:url('/wiki/detail-'.$gid.'-'.$vo["hash"])}">
|
<a class="{if condition="$hash == $vo['hash']"}active{/if} teal item" href="{:url('/wiki/detail/'.$groupHash.'/'.$vo["hash"])}">
|
||||||
{:substr($vo['hash'], 0, 11)}...({:mb_substr($vo['info'], 0, 3)}...)
|
{:substr($vo['hash'], 0, 11)}...({:mb_substr($vo['info'], 0, 3)}...)
|
||||||
<div class="ui {if condition="$hash == $vo['hash']"}teal{/if} label"> > </div>
|
<div class="ui {if condition="$hash == $vo['hash']"}teal{/if} label"> > </div>
|
||||||
</a>
|
</a>
|
||||||
@ -45,7 +45,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="twelve wide column">
|
<div class="twelve wide column">
|
||||||
<div class="ui floating message" id="detail" style="overflow: auto;">
|
<div class="ui floating message" id="detail" style="overflow: auto;">
|
||||||
<h2 class='ui header'>接口唯一标识:<a target="_blank" href="{$http_type}{$_SERVER['HTTP_HOST']}/api/{$hash}">{$hash}</a>({$detail['apiClass']})</h2><br />
|
<h2 class='ui header'>接口唯一标识:<a target="_blank" href="{$http_type}{$_SERVER['HTTP_HOST']}/api/{$hash}">{$hash}</a>{if condition="$detail['isTest'] == 1"}({$detail['apiClass']}){/if}</h2><br />
|
||||||
<div class="ui raised segment">
|
<div class="ui raised segment">
|
||||||
<span class="ui red ribbon large label">接口说明</span>
|
<span class="ui red ribbon large label">接口说明</span>
|
||||||
{if condition="$detail['status'] eq 0 "}
|
{if condition="$detail['status'] eq 0 "}
|
||||||
|
2
public/static/.gitignore
vendored
2
public/static/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
*
|
|
||||||
!.gitignore
|
|
BIN
public/static/jsonFormater/Collapsed.gif
Normal file
BIN
public/static/jsonFormater/Collapsed.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 215 B |
BIN
public/static/jsonFormater/Expanded.gif
Normal file
BIN
public/static/jsonFormater/Expanded.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 206 B |
35
public/static/jsonFormater/jsonFormater.css
Normal file
35
public/static/jsonFormater/jsonFormater.css
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
@charset "utf-8";
|
||||||
|
/* CSS Document */
|
||||||
|
.jf-ObjectBrace {
|
||||||
|
color: #00AA00;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.jf-ArrayBrace {
|
||||||
|
color: #0033FF;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.jf-PropertyName {
|
||||||
|
color: #CC0000;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.jf-String {
|
||||||
|
color: #007777;
|
||||||
|
}
|
||||||
|
.jf-Number {
|
||||||
|
color: #AA00AA;
|
||||||
|
}
|
||||||
|
.jf-Boolean {
|
||||||
|
color: #0000FF;
|
||||||
|
}
|
||||||
|
.jf-Null {
|
||||||
|
color: #0000FF;
|
||||||
|
}
|
||||||
|
.jf-Comma {
|
||||||
|
color: #000000;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
pre.jf-CodeContainer {
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
text-align: left;
|
||||||
|
}
|
202
public/static/jsonFormater/jsonFormater.js
Normal file
202
public/static/jsonFormater/jsonFormater.js
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
function JsonFormater(opt) {
|
||||||
|
this.options = $.extend({
|
||||||
|
dom: '',
|
||||||
|
tabSize: 2,
|
||||||
|
singleTab: " ",
|
||||||
|
quoteKeys: true,
|
||||||
|
imgCollapsed: "images/Collapsed.gif",
|
||||||
|
imgExpanded: "images/Expanded.gif",
|
||||||
|
isCollapsible: true
|
||||||
|
}, opt || {});
|
||||||
|
this.isFormated = false;
|
||||||
|
this.obj = {
|
||||||
|
_dateObj: new Date(),
|
||||||
|
_regexpObj: new RegExp()
|
||||||
|
};
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
JsonFormater.prototype = {
|
||||||
|
init: function () {
|
||||||
|
this.tab = this.multiplyString(this.options.tabSize, this.options.singleTab);
|
||||||
|
this.bindEvent();
|
||||||
|
},
|
||||||
|
doFormat: function (json) {
|
||||||
|
var html;
|
||||||
|
var obj;
|
||||||
|
try {
|
||||||
|
if(typeof json == 'object'){
|
||||||
|
obj = [json];
|
||||||
|
}else{
|
||||||
|
if (json == ""){
|
||||||
|
json = "\"\"";
|
||||||
|
}
|
||||||
|
obj = eval("[" + json + "]");
|
||||||
|
}
|
||||||
|
html = this.ProcessObject(obj[0], 0, false, false, false);
|
||||||
|
$(this.options.dom).addClass('jf-CodeContainer');
|
||||||
|
$(this.options.dom).html(html);
|
||||||
|
this.isFormated = true;
|
||||||
|
} catch (e) {
|
||||||
|
alert("JSON数据格式不正确:\n" + e.message);
|
||||||
|
$(this.options.dom).html("");
|
||||||
|
this.isFormated = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bindEvent: function () {
|
||||||
|
var that = this;
|
||||||
|
$(this.options.dom).off('click','.imgToggle');
|
||||||
|
$(this.options.dom).on('click', '.imgToggle', function () {
|
||||||
|
if (that.isFormated == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
that.makeContentVisible($(this).parent().next(), !$(this).data('status'));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
expandAll: function () {
|
||||||
|
if (this.isFormated == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var that = this;
|
||||||
|
this.traverseChildren($(this.options.dom), function(element){
|
||||||
|
if(element.hasClass('jf-collapsible')){
|
||||||
|
that.makeContentVisible(element, true);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
},
|
||||||
|
collapseAll: function () {
|
||||||
|
if (this.isFormated == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var that = this;
|
||||||
|
this.traverseChildren($(this.options.dom), function(element){
|
||||||
|
if(element.hasClass('jf-collapsible')){
|
||||||
|
that.makeContentVisible(element, false);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
},
|
||||||
|
collapseLevel: function(level){
|
||||||
|
if (this.isFormated == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var that = this;
|
||||||
|
this.traverseChildren($(this.options.dom), function(element, depth){
|
||||||
|
if(element.hasClass('jf-collapsible')){
|
||||||
|
if(depth >= level){
|
||||||
|
that.makeContentVisible(element, false);
|
||||||
|
}else{
|
||||||
|
that.makeContentVisible(element, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
},
|
||||||
|
isArray: function (obj) {
|
||||||
|
return obj &&
|
||||||
|
typeof obj === 'object' &&
|
||||||
|
typeof obj.length === 'number' && !(obj.propertyIsEnumerable('length'));
|
||||||
|
},
|
||||||
|
getRow: function (indent, data, isPropertyContent) {
|
||||||
|
var tabs = "";
|
||||||
|
if (!isPropertyContent) {
|
||||||
|
tabs = this.multiplyString(indent, this.tab);
|
||||||
|
}
|
||||||
|
if (data != null && data.length > 0 && data.charAt(data.length - 1) != "\n") {
|
||||||
|
data = data + "\n";
|
||||||
|
}
|
||||||
|
return tabs + data;
|
||||||
|
},
|
||||||
|
formatLiteral: function (literal, quote, comma, indent, isArray, style) {
|
||||||
|
if (typeof literal == 'string') {
|
||||||
|
literal = literal.split("<").join("<").split(">").join(">");
|
||||||
|
}
|
||||||
|
var str = "<span class='jf-" + style + "'>" + quote + literal + quote + comma + "</span>";
|
||||||
|
if (isArray) str = this.getRow(indent, str);
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
formatFunction: function (indent, obj) {
|
||||||
|
var tabs;
|
||||||
|
var i;
|
||||||
|
var funcStrArray = obj.toString().split("\n");
|
||||||
|
var str = "";
|
||||||
|
tabs = this.multiplyString(indent, this.tab);
|
||||||
|
for (i = 0; i < funcStrArray.length; i++) {
|
||||||
|
str += ((i == 0) ? "" : tabs) + funcStrArray[i] + "\n";
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
multiplyString: function (num, str) {
|
||||||
|
var result = '';
|
||||||
|
for (var i = 0; i < num; i++) {
|
||||||
|
result += str;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
traverseChildren: function (element, func, depth) {
|
||||||
|
var length = element.children().length;
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
this.traverseChildren(element.children().eq(i), func, depth + 1);
|
||||||
|
}
|
||||||
|
func(element, depth);
|
||||||
|
},
|
||||||
|
makeContentVisible : function(element, visible){
|
||||||
|
var img = element.prev().find('img');
|
||||||
|
if(visible){
|
||||||
|
element.show();
|
||||||
|
img.attr('src', this.options.imgExpanded);
|
||||||
|
img.data('status', 1);
|
||||||
|
}else{
|
||||||
|
element.hide();
|
||||||
|
img.attr('src', this.options.imgCollapsed);
|
||||||
|
img.data('status', 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ProcessObject: function (obj, indent, addComma, isArray, isPropertyContent) {
|
||||||
|
var html = "";
|
||||||
|
var comma = (addComma) ? "<span class='jf-Comma'>,</span> " : "";
|
||||||
|
var type = typeof obj;
|
||||||
|
var clpsHtml = "";
|
||||||
|
var prop;
|
||||||
|
if (this.isArray(obj)) {
|
||||||
|
if (obj.length == 0) {
|
||||||
|
html += this.getRow(indent, "<span class='jf-ArrayBrace'>[ ]</span>" + comma, isPropertyContent);
|
||||||
|
} else {
|
||||||
|
clpsHtml = this.options.isCollapsible ? "<span><img class='imgToggle' data-status='1' src='" + this.options.imgExpanded + "'/></span><span class='jf-collapsible'>" : "";
|
||||||
|
html += this.getRow(indent, "<span class='jf-ArrayBrace'>[</span>" + clpsHtml, isPropertyContent);
|
||||||
|
for (var i = 0; i < obj.length; i++) {
|
||||||
|
html += this.ProcessObject(obj[i], indent + 1, i < (obj.length - 1), true, false);
|
||||||
|
}
|
||||||
|
clpsHtml = this.options.isCollapsible ? "</span>" : "";
|
||||||
|
html += this.getRow(indent, clpsHtml + "<span class='jf-ArrayBrace'>]</span>" + comma);
|
||||||
|
}
|
||||||
|
} else if (type == 'object') {
|
||||||
|
if (obj == null) {
|
||||||
|
html += this.formatLiteral("null", "", comma, indent, isArray, "Null");
|
||||||
|
} else {
|
||||||
|
var numProps = 0;
|
||||||
|
for (prop in obj) numProps++;
|
||||||
|
if (numProps == 0) {
|
||||||
|
html += this.getRow(indent, "<span class='jf-ObjectBrace'>{ }</span>" + comma, isPropertyContent);
|
||||||
|
} else {
|
||||||
|
clpsHtml = this.options.isCollapsible ? "<span><img class='imgToggle' data-status='1' src='" + this.options.imgExpanded + "'/></span><span class='jf-collapsible'>" : "";
|
||||||
|
html += this.getRow(indent, "<span class='jf-ObjectBrace'>{</span>" + clpsHtml, isPropertyContent);
|
||||||
|
var j = 0;
|
||||||
|
for (prop in obj) {
|
||||||
|
var quote = this.options.quoteKeys ? "\"" : "";
|
||||||
|
html += this.getRow(indent + 1, "<span class='jf-PropertyName'>" + quote + prop + quote + "</span>: " + this.ProcessObject(obj[prop], indent + 1, ++j < numProps, false, true));
|
||||||
|
}
|
||||||
|
clpsHtml = this.options.isCollapsible ? "</span>" : "";
|
||||||
|
html += this.getRow(indent, clpsHtml + "<span class='jf-ObjectBrace'>}</span>" + comma);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (type == 'number') {
|
||||||
|
html += this.formatLiteral(obj, "", comma, indent, isArray, "Number");
|
||||||
|
} else if (type == 'boolean') {
|
||||||
|
html += this.formatLiteral(obj, "", comma, indent, isArray, "Boolean");
|
||||||
|
}else if (type == 'undefined') {
|
||||||
|
html += this.formatLiteral("undefined", "", comma, indent, isArray, "Null");
|
||||||
|
} else {
|
||||||
|
html += this.formatLiteral(obj.toString().split("\\").join("\\\\").split('"').join('\\"'), "\"", comma, indent, isArray, "String");
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user