add single mock.html template

This commit is contained in:
oppofind 2020-12-17 23:59:43 +08:00
parent 293ca2a81d
commit 8cf0a0c377
9 changed files with 1009 additions and 38 deletions

View File

@ -125,7 +125,7 @@ public class DocBuilderTemplate extends BaseDocBuilderTemplate {
tpl.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), errorCodeList);
tpl.binding(TemplateVariable.VERSION_LIST.getVariable(), config.getRevisionLogs());
tpl.binding(TemplateVariable.VERSION.getVariable(), now);
tpl.binding(TemplateVariable.INDEX_ALIAS.getVariable(), apiDoc.getAlias());
tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime);
tpl.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName());
tpl.binding(TemplateVariable.REQUEST_EXAMPLE.getVariable(), config.isRequestExample());
@ -164,13 +164,15 @@ public class DocBuilderTemplate extends BaseDocBuilderTemplate {
/**
* build error_code html
*
* @param config api config
* @param apiDocList list data of Api doc
* @param template template
* @param outPutFileName output file
* @param config api config
* @param javaProjectBuilder javaProjectBuilder
* @param apiDocList list data of Api doc
* @param template template
* @param outPutFileName output file
* @param indexAlias index alias
*/
public void buildErrorCodeDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder,
List<ApiDoc> apiDocList, String template, String outPutFileName) {
List<ApiDoc> apiDocList, String template, String outPutFileName, String indexAlias) {
List<ApiErrorCode> errorCodeList = errorCodeDictToList(config);
Template errorTemplate = BeetlTemplateUtil.getByName(template);
errorTemplate.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName());
@ -183,6 +185,7 @@ public class DocBuilderTemplate extends BaseDocBuilderTemplate {
}
List<ApiDocDict> apiDocDictList = buildDictionary(config, javaProjectBuilder);
errorTemplate.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList);
errorTemplate.binding(TemplateVariable.INDEX_ALIAS.getVariable(), indexAlias);
errorTemplate.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList);
errorTemplate.binding(TemplateVariable.BACKGROUND.getVariable(), HighlightStyle.getBackgroundColor(style));
errorTemplate.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), errorCodeList);
@ -199,8 +202,10 @@ public class DocBuilderTemplate extends BaseDocBuilderTemplate {
* @param apiDocList list data of Api doc
* @param template template
* @param outPutFileName output file
* @param indexAlias index alias
*/
public void buildDirectoryDataDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder, List<ApiDoc> apiDocList, String template, String outPutFileName) {
public void buildDirectoryDataDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder, List<ApiDoc> apiDocList,
String template, String outPutFileName, String indexAlias) {
List<ApiDocDict> directoryList = buildDictionary(config, javaProjectBuilder);
Template mapper = BeetlTemplateUtil.getByName(template);
mapper.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName());
@ -213,6 +218,7 @@ public class DocBuilderTemplate extends BaseDocBuilderTemplate {
mapper.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 2);
}
mapper.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList);
mapper.binding(TemplateVariable.INDEX_ALIAS.getVariable(), indexAlias);
mapper.binding(TemplateVariable.BACKGROUND.getVariable(), HighlightStyle.getBackgroundColor(style));
mapper.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), errorCodeList);
setDirectoryLanguageVariable(config, mapper);

View File

@ -73,45 +73,56 @@ public class HtmlApiDocBuilder {
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
IDocBuildTemplate docBuildTemplate = new SpringBootDocBuildTemplate();
List<ApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
Template indexCssTemplate = BeetlTemplateUtil.getByName(ALL_IN_ONE_CSS);
FileUtil.nioWriteFile(indexCssTemplate.render(), config.getOutPath() + FILE_SEPARATOR + ALL_IN_ONE_CSS);
if (config.isAllInOne()) {
Template indexCssTemplate = BeetlTemplateUtil.getByName(ALL_IN_ONE_CSS);
FileUtil.nioWriteFile(indexCssTemplate.render(), config.getOutPath() + FILE_SEPARATOR + ALL_IN_ONE_CSS);
if (StringUtils.isNotEmpty(config.getAllInOneDocFileName())) {
INDEX_HTML = config.getAllInOneDocFileName();
}
if(config.isCreateDebugPage()){
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, DEBUG_PAGE_TPL, DEBUG_PAGE_TPL);
if (config.isCreateDebugPage()) {
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, DEBUG_PAGE_TPL, DEBUG_PAGE_ALL_TPL);
} else {
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, ALL_IN_ONE_HTML_TPL, INDEX_HTML);
}
} else {
Template indexCssTemplate = BeetlTemplateUtil.getByName(ALL_IN_ONE_CSS);
FileUtil.nioWriteFile(indexCssTemplate.render(), config.getOutPath() + FILE_SEPARATOR + ALL_IN_ONE_CSS);
buildDoc(builderTemplate,apiDocList,config,javaProjectBuilder);
builderTemplate.buildErrorCodeDoc(config,javaProjectBuilder,apiDocList,
"html/error.html","error.html");
builderTemplate.buildDirectoryDataDoc(config,javaProjectBuilder,apiDocList,
"html/dict.html","dict.html");
String indexAlias;
if (config.isCreateDebugPage()) {
indexAlias = "mock";
buildDoc(builderTemplate, apiDocList, config, javaProjectBuilder, DEBUG_PAGE_SINGLE_TPL, indexAlias);
} else {
indexAlias = "api";
buildDoc(builderTemplate, apiDocList, config, javaProjectBuilder, SINGLE_INDEX_HTML_TPL, indexAlias);
}
builderTemplate.buildErrorCodeDoc(config, javaProjectBuilder, apiDocList, SINGLE_ERROR_HTML_TPL,
"error.html",indexAlias);
builderTemplate.buildDirectoryDataDoc(config, javaProjectBuilder, apiDocList,
SINGLE_DICT_HTML_TPL, "dict.html",indexAlias);
}
}
/**
* build ever controller api
*
* @param apiDocList list of api doc
* @param config ApiConfig
* @param builderTemplate DocBuilderTemplate
* @param apiDocList list of api doc
* @param config ApiConfig
* @param javaProjectBuilder ProjectDocConfigBuilder
* @param template template
* @param outName outName
*/
private static void buildDoc(DocBuilderTemplate builderTemplate,List<ApiDoc> apiDocList,
ApiConfig config,JavaProjectBuilder javaProjectBuilder) {
private static void buildDoc(DocBuilderTemplate builderTemplate, List<ApiDoc> apiDocList,
ApiConfig config, JavaProjectBuilder javaProjectBuilder,
String template, String outName) {
FileUtil.mkdirs(config.getOutPath());
int index = 0;
for (ApiDoc doc : apiDocList) {
if(index == 0){
doc.setAlias("api");
if (index == 0) {
doc.setAlias(outName);
}
builderTemplate.buildDoc(apiDocList,config,javaProjectBuilder,"html/index.html",
doc.getAlias() + ".html",doc);
index ++;
builderTemplate.buildDoc(apiDocList, config, javaProjectBuilder, template,
doc.getAlias() + ".html", doc);
index++;
}
}
}

View File

@ -54,6 +54,16 @@ public interface DocGlobalConstants {
String DEBUG_PAGE_TPL = "mock.html";
String DEBUG_PAGE_ALL_TPL = "mock-all.html";
String DEBUG_PAGE_SINGLE_TPL = "html/mock.html";
String SINGLE_INDEX_HTML_TPL = "html/index.html";
String SINGLE_ERROR_HTML_TPL = "html/error.html";
String SINGLE_DICT_HTML_TPL = "html/dict.html";
String ALL_IN_ONE_CSS = "AllInOne.css";
String RPC_API_DOC_ADOC_TPL = "dubbo/Dubbo.adoc";

View File

@ -52,7 +52,8 @@ public enum TemplateVariable {
REQUEST_EXAMPLE("isRequestExample"),
RESPONSE_EXAMPLE("isResponseExample"),
RESPONSE_LIST("respList"),
ORDER("order");
ORDER("order"),
INDEX_ALIAS("alias");
private String variable;

View File

@ -28,12 +28,12 @@
<ul id="accordion" class="sectlevel1">
<%for(api in apiDocList){%>
<%if(apiLP.first){%>
<li><a class="dd" href="api.html#header">${api.order}.&nbsp;${api.desc}</a>
<li><a class="dd" href="${alias}.html#header">${api.order}.&nbsp;${api.desc}</a>
<ul class="sectlevel2" style="display: none">
<%for(doc in api.list){%>
<li><%if(doc.deprecated){%><a href="api.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;<span
<li><%if(doc.deprecated){%><a href="${alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;<span
class="line-through">${doc.desc}</span></a><%}else{%><a
href="api.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
href="${alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
</li>
<%}%>
</ul>

View File

@ -29,12 +29,12 @@
<%for(api in apiDocList){%>
<%if(apiLP.first){%>
<li>
<a class="dd" href="api.html#header">${api.order}.&nbsp;${api.desc}</a>
<a class="dd" href="${alias}.html#header">${api.order}.&nbsp;${api.desc}</a>
<ul class="sectlevel2" style="display: none">
<%for(doc in api.list){%>
<li><%if(doc.deprecated){%><a href="api.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;<span
<li><%if(doc.deprecated){%><a href="${alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;<span
class="line-through">${doc.desc}</span></a><%}else{%><a
href="api.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
href="${alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
</li>
<%}%>
</ul>

View File

@ -37,12 +37,12 @@
}%>
<%if(apiLP.first){%>
<li class="${liClass}">
<a class="dd" href="api.html#header">${api.order}.&nbsp;${api.desc}</a>
<a class="dd" href="${alias}.html#header">${api.order}.&nbsp;${api.desc}</a>
<ul class="sectlevel2" style="${myStyle}">
<%for(doc in api.list){%>
<li><%if(doc.deprecated){%><a href="api.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;<span
<li><%if(doc.deprecated){%><a href="${alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;<span
class="line-through">${doc.desc}</span></a><%}else{%><a
href="api.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
href="${alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
</li>
<%}%>
</ul>

View File

@ -0,0 +1,548 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="smart-doc">
<%if(isNotEmpty(projectName)){%><title>${projectName}</title><%}else{%><title>API Reference</title><%}%>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="AllInOne.css?v=${version}"/>
<script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.js"></script>
</head>
<body class="book toc2 toc-left">
<div id="header">
<%if(isNotEmpty(projectName)){%><h1>${projectName}</h1><%}%>
<div id="toc" class="toc2">
<div id="book-search-input"><input id="search" type="text" placeholder="Type to search"></div>
<div id="toctitle"><span>API Reference</span></div>
<ul id="accordion" class="sectlevel1">
<%for(api in apiDocList){%>
<%
var myStyle = "display: none";
var liClass = "";
if(api.order==order){
myStyle= "display: block";
liClass = "open";
}%>
<%if(apiLP.first){%>
<li class="${liClass}">
<a class="dd" href="${api.alias}.html#header">${api.order}.&nbsp;${api.desc}</a>
<ul class="sectlevel2" style="${myStyle}">
<%for(doc in api.list){%>
<li><%if(doc.deprecated){%><a href="${api.alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;<span
class="line-through">${doc.desc}</span></a><%}else{%><a
href="${api.alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
</li>
<%}%>
</ul>
</li>
<%}else{%>
<li class="${liClass}">
<a class="dd" href="${api.alias}.html#header">${api.order}.&nbsp;${api.desc}</a>
<ul class="sectlevel2" style="${myStyle}">
<%for(doc in api.list){%>
<li><%if(doc.deprecated){%>
<a href="${api.alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;<span
class="line-through">${doc.desc}</span></a><%}else{%><a
href="${api.alias}.html#_${api.order}_${doc.order}_${doc.desc}">${api.order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
</li>
<%}%>
</ul>
</li>
<%}%><%}%><%if(isNotEmpty(errorCodeList)){%>
<li><a href="error.html#header">${apiDocList.~size+1}.${errorListTitle}</a></li>
<%}%><%if(isNotEmpty(dictList)){%>
<li><a class="dd" href="dict.html#header">${dictListOrder}.&nbsp;${dictListTitle}</a>
<ul class="sectlevel2"><%for(dict in dictList){%>
<li><a href="dict.html#_${dictListOrder}_${dict.order}_${dict.title}">${dictListOrder}.${dict.order}.&nbsp;${dict.title}</a>
</li>
<%}%>
</ul>
</li>
<%}%>
</ul>
</div>
</div>
<div id="content">
<div class="sect1"><h2 id="_${desc}"><a class="anchor" href="#_${desc}"></a><a class="link" href="#_${desc}">${order}.&nbsp;${desc}</a>
</h2>
<div class="sectionbody">
<%for(doc in list){%>
<div class="sect2"><h3 id="_${order}_${doc.order}_${doc.desc}"><a class="anchor"
href="#_${order}_${doc.order}_${doc.desc}"></a><%if(doc.deprecated){%><a
class="link" href="#_${order}_${doc.order}_${doc.desc}">${order}.${doc.order}.&nbsp;<span
class="line-through">${doc.desc}</span></a><%}else{%><a class="link"
href="#_${order}_${doc.order}_${doc.desc}">${order}.${doc.order}.&nbsp;${doc.desc}</a><%}%>
</h3>
<div class="paragraph" id="${doc.methodId}-url" data-url="${doc.url}" data-download="${doc.download}"><p><strong>URL:</strong><a href="${doc.url}" class="bare">&nbsp;${doc.url}</a>
</p></div>
<div class="paragraph" id="${doc.methodId}-method" data-method="${doc.type}"><p><strong>Type:</strong>&nbsp;${doc.type}</p></div>
<%if(isNotEmpty(doc.author)){%>
<div class="paragraph"><p><strong>Author:</strong>&nbsp;${doc.author}</p></div>
<%}%>
<div class="paragraph" id="${doc.methodId}-content-type" data-content-type="${doc.contentType}"><p><strong>Content-Type:</strong>&nbsp;${doc.contentType}</p></div>
<div class="paragraph"><p><strong>Description:</strong>&nbsp;${doc.detail}</p></div>
<%if(isNotEmpty(doc.requestHeaders)){%>
<div class="paragraph"><p><strong>Request-headers:</strong></p></div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 5%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">
<div class="checkbox"><input type="checkbox" class="check-all"
id="${doc.methodId}-header-checkbox"
name="${doc.methodId}-header-checkbox" checked="checked"><label
for="${doc.methodId}-header-checkbox"></label></div>
</th>
<th class="tableblock halign-left valign-top">Header</th>
<th class="tableblock halign-left valign-top">Value</th>
<th class="tableblock halign-left valign-top">Type</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody id="${doc.methodId}-header"><%for(header in doc.requestHeaders){%>
<tr>
<td class="tableblock halign-left valign-top">
<div class="checkbox"><input type="checkbox" id="${doc.methodId}-header-${header.name}"
name="${doc.methodId}-header-checkbox" checked="checked"><label
for="${doc.methodId}-header-${header.name}"></label></div>
</td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.name}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><input name="${header.name}"
type="text"
value="${header.value}"/>
</td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.type}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.required}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${header.desc}</p></td>
</tr>
<%}%>
</tbody>
</table>
<%}%><%if(isNotEmpty(doc.pathParams)){%>
<div class="paragraph"><p><strong>Path-parameters:</strong></p></div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 5%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">
<div class='checkbox'><input type="checkbox" class="check-all"
id="${doc.methodId}-path-checkbox"
name="${doc.methodId}-path-checkbox" checked="checked"><label
for='${doc.methodId}-path-checkbox'></label></div>
</th>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Value</th>
<th class="tableblock halign-left valign-top">Type</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody id="${doc.methodId}-path-params"><%for(param in doc.pathParams){%>
<tr>
<td class="tableblock halign-left valign-top">
<div class="checkbox"><input type="checkbox" id="${doc.methodId}-path-${param.field}"
checked="checked" name="${doc.methodId}-path-checkbox"><label
for="${doc.methodId}-path-${param.field}"></label></div>
</td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.field}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><input name="${param.field}"
type="text"
value="${param.value}"/>
</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.type}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.required}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.desc}</p></td>
</tr>
<%}%>
</tbody>
</table>
<%}%><%if(isNotEmpty(doc.queryParams)){%>
<div class="paragraph"><p><strong>Query-parameters:</strong></p></div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 5%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
<col style="width: 19%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">
<div class='checkbox'><input type="checkbox" class="check-all"
id="${doc.methodId}-query-checkbox" checked="checked"
name="${doc.methodId}-query-checkbox"><label
for="${doc.methodId}-query-checkbox"></label></div>
</th>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Value</th>
<th class="tableblock halign-left valign-top">Type</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody id="${doc.methodId}-query-params"><%for(param in doc.queryParams){%>
<tr>
<td class="tableblock halign-left valign-top">
<div class='checkbox'><input type="checkbox" id="${doc.methodId}-query-${param.field}"
checked="checked" name="${doc.methodId}-query-checkbox"><label
for="${doc.methodId}-query-${param.field}"></label></div>
</td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.field}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">
<%if(param.type=="file"){%><input name="${param.field}" type="file"
value="${param.value}"/><%}else{%><input
name="${param.field}" type="text" value="${param.value}"/><%}%></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.type}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.required}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.desc}</p></td>
</tr>
<%}%>
</tbody>
</table>
<%}%><%if(isNotEmpty(doc.requestParams)){%>
<div class="paragraph"><p><strong>Body-parameters:</strong></p></div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Type</th>
<th class="tableblock halign-left valign-top">Required</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody><%for(param in doc.requestParams){%>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.field}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.type}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.required}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.desc}</p></td>
</tr>
<%}%>
</tbody>
</table>
<%}%>
<%if(isNotEmpty(doc.requestExample.jsonBody)&&isRequestExample){%>
<div class="paragraph"><p><strong>Request-body:</strong></p></div>
<div class="listingblock">
<div class="content"><textarea id="${doc.methodId}-body">${doc.requestExample.jsonBody}</textarea>
</div>
</div>
<%}%>
<%if(isNotEmpty(doc.responseParams)){%>
<div class="paragraph"><p><strong>Response-fields:</strong></p></div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Field</th>
<th class="tableblock halign-left valign-top">Type</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Since</th>
</tr>
</thead>
<tbody><%for(param in doc.responseParams){%>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.field}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.type}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.desc}</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">${param.version}</p></td>
</tr>
<%}%>
</tbody>
</table>
<%}%>
<div class="paragraph">
<p><strong>
<button class="send-button" data-id="${doc.methodId}">Send Request</button>
</strong><span id="${doc.methodId}-resp-status"></span></p>
</div>
<%if(isNotEmpty(doc.responseUsage)&&isResponseExample){%>
<div class="paragraph"><p><strong>Response-example:</strong></p></div>
<div class="listingblock">
<div class="content" id="${doc.methodId}-response">
<pre><code class="json">${doc.responseUsage}</code></pre>
</div>
</div>
<%}%>
<%if(isNotEmpty(doc.requestUsage)&&isRequestExample){%>
<div class="paragraph"><p><strong>Curl-example:</strong></p></div>
<div class="listingblock">
<div class="content">
<pre><code class="bash">${doc.requestUsage}</code></pre>
</div>
</div>
<%}%>
</div>
<%}%>
</div>
</div>
<footer class="page-footer"><span class="copyright">Generated by smart-doc at 2020-12-15 00:22:14</span><span
class="footer-modification">Suggestions,contact,support and error reporting on<a
href="https://gitee.com/smart-doc-team/smart-doc" target="_blank">&nbsp;Gitee</a>&nbsp;or<a
href="https://github.com/smart-doc-group/smart-doc.git" target="_blank">&nbsp;Github</a></span>
</footer>
</div>
<script>
$(function () {
const Accordion = function (el, multiple) {
this.el = el || {};
this.multiple = multiple || false;
const links = this.el.find('.dd');
links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
};
Accordion.prototype.dropdown = function (e) {
const $el = e.data.el;
const $this = $(this), $next = $this.next();
$next.slideToggle();
$this.parent().toggleClass('open');
if (!e.data.multiple) {
$el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
}
};
new Accordion($('#accordion'), false);
});
$('textarea').each(function () {
this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
}).on('input', function () {
this.style.height = '80px';
this.style.height = (this.scrollHeight) + 'px';
});
$("button").on("click", function () {
const $this = $(this);
const id = $this.data("id");
console.log("method-id=>" + id);
let body = $("#" + id + "-body").val();
// header
const $headerElement = $("#" + id + "-header");
const headersData = getInputData($headerElement);
// body param
const $paramElement = $("#" + id + "-param");
let bodyParamData = getInputData($paramElement)
// path param
const $pathElement = $("#" + id + "-path-params")
const pathParamData = getInputData($pathElement)
// query param
const $queryElement = $("#" + id + "-query-params")
const url = $("#" + id + "-url").data("url");
const isDownload = $("#" + id + "-url").data("download");
const method = $("#" + id + "-method").data("method");
const contentType = $("#" + id + "-content-type").data("content-type");
console.log("request-headers=>" + JSON.stringify(headersData))
console.log("path-params=>" + JSON.stringify(pathParamData))
console.log("body-params=>" + JSON.stringify(bodyParamData))
console.log("json-body=>" + body);
let queryParamData = "";
if (isDownload) {
queryParamData = getInputData($queryElement);
download(url, headersData, pathParamData, queryParamData, bodyParamData, method, contentType);
return;
}
const ajaxOptions = {};
let finalUrl = "";
if ("multipart/form-data" == contentType) {
finalUrl = castToGetUri(url, pathParamData);
queryParamData = getInputData($queryElement, true)
body = queryParamData;
ajaxOptions.processData = false;
ajaxOptions.contentType = false;
} else {
queryParamData = getInputData($queryElement)
finalUrl = castToGetUri(url, pathParamData, queryParamData)
ajaxOptions.contentType = contentType;
}
console.log("query-params=>" + JSON.stringify(queryParamData));
console.log("url=>" + finalUrl)
ajaxOptions.headers = headersData
ajaxOptions.url = finalUrl
ajaxOptions.type = method
ajaxOptions.data = body;
const ajaxTime = new Date().getTime();
$.ajax(ajaxOptions).done(function (result, textStatus, jqXHR) {
$this.css("background", "#5cb85c");
$("#" + id + "-response").find("pre").text(JSON.stringify(result, null, 4));
const totalTime = new Date().getTime() - ajaxTime;
$("#" + id + "-resp-status").html("&nbsp;Status:&nbsp;" + jqXHR.status + "&nbsp;&nbsp;" + jqXHR.statusText + "&nbsp;&nbsp;&nbsp;&nbsp;Time:&nbsp;" + totalTime + "&nbsp;ms")
}).fail(function (jqXHR) {
$this.css("background", "#D44B47");
$("#" + id + "-response").find("pre").text(JSON.stringify(jqXHR.responseJSON, null, 4));
const totalTime = new Date().getTime() - ajaxTime;
$("#" + id + "-resp-status").html("&nbsp;Status:&nbsp;" + jqXHR.status + "&nbsp;&nbsp;" + jqXHR.statusText + "&nbsp;&nbsp;&nbsp;&nbsp;Time:&nbsp;" + totalTime + "&nbsp;ms")
}).always(function () {
});
})
$(".check-all").on("click", function () {
const checkboxName = $(this).prop("name");
const checked = $(this).is(':checked');
if (!checked) {
$(this).removeAttr("checked");
} else {
$(this).prop("checked", true);
}
$('input[name="' + checkboxName + '"]').each(function () {
if (!checked) {
$(this).removeAttr("checked");
} else {
$(this).prop("checked", true);
}
})
})
function castToGetUri(url, pathParams, params) {
if (pathParams instanceof Object && !(pathParams instanceof Array)) {
url = url.format(pathParams)
}
if (params instanceof Object && !(params instanceof Array)) {
const pm = params || {};
const arr = [];
arr.push(url);
let j = 0;
for (const i in pm) {
if (j === 0) {
arr.push("?");
arr.push(i + "=" + pm[i]);
} else {
arr.push("&" + i + "=" + pm[i]);
}
j++;
}
return arr.join("");
} else {
return url;
}
}
function getInputData(element, returnFormDate) {
const formData = new FormData();
$(element).find("tr").each(function (i) {
const checked = $(this).find('td:eq(0)').children(".checkbox").children("input").is(':checked');
if (checked) {
const input = $(this).find('td:eq(2) input');
console.log("input type:" + $(input).attr("type"))
const name = $(input).attr("name");
if ($(input).attr("type") == "file") {
formData.append(name, $(input)[0].files[0]);
} else {
const val = $(input).val();
formData.append(name, val);
}
}
});
if (returnFormDate) {
return formData;
}
const headersData = {};
formData.forEach((value, key) => headersData[key] = value);
return headersData;
}
String.prototype.format = function (args) {
let reg;
if (arguments.length > 0) {
let result = this;
if (arguments.length == 1 && typeof (args) == "object") {
for (const key in args) {
reg = new RegExp("({" + key + "})", "g");
result = result.replace(reg, args[key]);
}
} else {
for (let i = 0; i < arguments.length; i++) {
if (arguments[i] == undefined) {
return "";
} else {
reg = new RegExp("({[" + i + "]})", "g");
result = result.replace(reg, arguments[i]);
}
}
}
return result;
} else {
return this;
}
}
function download(url, headersData, pathParamData, queryParamData, bodyParamData, method, contentType) {
url = castToGetUri(url, pathParamData, queryParamData)
const xmlRequest = new XMLHttpRequest();
xmlRequest.open(method, url, true);
xmlRequest.setRequestHeader("Content-type", contentType);
for (let key in headersData) {
xmlRequest.setRequestHeader(key, headersData[key])
}
xmlRequest.responseType = "blob";
xmlRequest.onload = function () {
if (this.status === 200) {
let fileName = decodeURI(xmlRequest.getResponseHeader('filename'));
console.log(fileName);
const blob = this.response;
if (navigator.msSaveBlob) {
// IE10 can't do a[download], only Blobs:
window.navigator.msSaveBlob(blob, fileName);
return;
}
if (window.URL) { // simple fast and modern way using Blob and URL:
const a = document.createElement("a");
document.body.appendChild(a);
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
}
console.log(fileName);
} else {
console.log("download failed");
}
};
try {
xmlRequest.send(bodyParamData);
} catch (e) {
console.error("Failed to send data", e);
}
}
</script>
</body>
</html>

File diff suppressed because one or more lines are too long