diff --git a/src/main/java/com/power/doc/builder/DocBuilderTemplate.java b/src/main/java/com/power/doc/builder/DocBuilderTemplate.java index e730a45..271dbd4 100644 --- a/src/main/java/com/power/doc/builder/DocBuilderTemplate.java +++ b/src/main/java/com/power/doc/builder/DocBuilderTemplate.java @@ -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 apiDocList, String template, String outPutFileName) { + List apiDocList, String template, String outPutFileName, String indexAlias) { List 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 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 apiDocList, String template, String outPutFileName) { + public void buildDirectoryDataDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder, List apiDocList, + String template, String outPutFileName, String indexAlias) { List 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); diff --git a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java index 3973637..105e870 100644 --- a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java +++ b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java @@ -73,45 +73,56 @@ public class HtmlApiDocBuilder { ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); IDocBuildTemplate docBuildTemplate = new SpringBootDocBuildTemplate(); List 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 apiDocList, - ApiConfig config,JavaProjectBuilder javaProjectBuilder) { + private static void buildDoc(DocBuilderTemplate builderTemplate, List 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++; } } } diff --git a/src/main/java/com/power/doc/constants/DocGlobalConstants.java b/src/main/java/com/power/doc/constants/DocGlobalConstants.java index 3984ece..a0bdd79 100644 --- a/src/main/java/com/power/doc/constants/DocGlobalConstants.java +++ b/src/main/java/com/power/doc/constants/DocGlobalConstants.java @@ -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"; diff --git a/src/main/java/com/power/doc/constants/TemplateVariable.java b/src/main/java/com/power/doc/constants/TemplateVariable.java index 0c3e9f8..3e1b761 100644 --- a/src/main/java/com/power/doc/constants/TemplateVariable.java +++ b/src/main/java/com/power/doc/constants/TemplateVariable.java @@ -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; diff --git a/src/main/resources/template/html/dict.html b/src/main/resources/template/html/dict.html index 42f741b..dc014da 100644 --- a/src/main/resources/template/html/dict.html +++ b/src/main/resources/template/html/dict.html @@ -28,12 +28,12 @@
    <%for(api in apiDocList){%> <%if(apiLP.first){%> -
  • ${api.order}. ${api.desc} +
  • ${api.order}. ${api.desc} diff --git a/src/main/resources/template/html/error.html b/src/main/resources/template/html/error.html index 39748c9..0393156 100644 --- a/src/main/resources/template/html/error.html +++ b/src/main/resources/template/html/error.html @@ -29,12 +29,12 @@ <%for(api in apiDocList){%> <%if(apiLP.first){%>
  • - ${api.order}. ${api.desc} + ${api.order}. ${api.desc} diff --git a/src/main/resources/template/html/index.html b/src/main/resources/template/html/index.html index 9e257d5..67c9ec1 100644 --- a/src/main/resources/template/html/index.html +++ b/src/main/resources/template/html/index.html @@ -37,12 +37,12 @@ }%> <%if(apiLP.first){%>
  • - ${api.order}. ${api.desc} + ${api.order}. ${api.desc} diff --git a/src/main/resources/template/html/mock.html b/src/main/resources/template/html/mock.html new file mode 100644 index 0000000..b8566d3 --- /dev/null +++ b/src/main/resources/template/html/mock.html @@ -0,0 +1,548 @@ + + + + + + + <%if(isNotEmpty(projectName)){%>${projectName}<%}else{%>API Reference<%}%> + + + + + + +
    +

    ${order}. ${desc} +

    +
    + <%for(doc in list){%> +

    <%if(doc.deprecated){%>${order}.${doc.order}. ${doc.desc}<%}else{%>${order}.${doc.order}. ${doc.desc}<%}%> +

    + +

    Type: ${doc.type}

    + <%if(isNotEmpty(doc.author)){%> +

    Author: ${doc.author}

    + <%}%> +

    Content-Type: ${doc.contentType}

    +

    Description: ${doc.detail}

    + <%if(isNotEmpty(doc.requestHeaders)){%> +

    Request-headers:

    + + + + + + + + + + + + + + + + + + + + <%for(header in doc.requestHeaders){%> + + + + + + + + + <%}%> + +
    +
    +
    HeaderValueTypeRequiredDescription
    +
    +

    ${header.name}

    +

    ${header.type}

    ${header.required}

    ${header.desc}

    + <%}%><%if(isNotEmpty(doc.pathParams)){%> +

    Path-parameters:

    + + + + + + + + + + + + + + + + + + + + <%for(param in doc.pathParams){%> + + + + + + + + + <%}%> + +
    +
    +
    ParameterValueTypeRequiredDescription
    +
    +

    ${param.field}

    +

    ${param.type}

    ${param.required}

    ${param.desc}

    + <%}%><%if(isNotEmpty(doc.queryParams)){%> +

    Query-parameters:

    + + + + + + + + + + + + + + + + + + + + <%for(param in doc.queryParams){%> + + + + + + + + + <%}%> + +
    +
    +
    ParameterValueTypeRequiredDescription
    +
    +

    ${param.field}

    + <%if(param.type=="file"){%><%}else{%><%}%>

    ${param.type}

    ${param.required}

    ${param.desc}

    + <%}%><%if(isNotEmpty(doc.requestParams)){%> +

    Body-parameters:

    + + + + + + + + + + + + + + + + + <%for(param in doc.requestParams){%> + + + + + + + <%}%> + +
    ParameterTypeRequiredDescription

    ${param.field}

    ${param.type}

    ${param.required}

    ${param.desc}

    + <%}%> + <%if(isNotEmpty(doc.requestExample.jsonBody)&&isRequestExample){%> +

    Request-body:

    +
    +
    +
    +
    + <%}%> + <%if(isNotEmpty(doc.responseParams)){%> +

    Response-fields:

    + + + + + + + + + + + + + + + + <%for(param in doc.responseParams){%> + + + + + + + <%}%> + +
    FieldTypeDescriptionSince

    ${param.field}

    ${param.type}

    ${param.desc}

    ${param.version}

    + <%}%> +
    +

    + +

    +
    + <%if(isNotEmpty(doc.responseUsage)&&isResponseExample){%> +

    Response-example:

    +
    +
    +
    ${doc.responseUsage}
    +
    +
    + <%}%> + <%if(isNotEmpty(doc.requestUsage)&&isRequestExample){%> +

    Curl-example:

    +
    +
    +
    ${doc.requestUsage}
    +
    +
    + <%}%> +
    + <%}%> +
    +
    +
    Generated by smart-doc at 2020-12-15 00:22:14Suggestions,contact,support and error reporting on Gitee or Github +
    +
    + + + diff --git a/src/main/resources/template/mock.html b/src/main/resources/template/mock.html index c3f8154..bd8fdf7 100644 --- a/src/main/resources/template/mock.html +++ b/src/main/resources/template/mock.html @@ -1,4 +1,399 @@ -<%if(isNotEmpty(projectName)){%>${projectName}<%}else{%>API Reference<%}%>
    <%if(isNotEmpty(revisionLogList)){%>
    <%for(revisionLog in revisionLogList){%><%}%>
    VersionUpdate TimeStatusAuthorDescription

    ${revisionLog.version}

    ${revisionLog.revisionTime}

    ${revisionLog.status}

    ${revisionLog.author}

    ${revisionLog.remarks}

    <%}%><%for(api in apiDocList){%>

    ${api.order}. ${api.desc}

    <%for(doc in api.list){%>

    <%if(doc.deprecated){%>${api.order}.${doc.order}. ${doc.desc}<%}else{%>${api.order}.${doc.order}. ${doc.desc}<%}%>

    Type: ${doc.type}

    <%if(isNotEmpty(doc.author)){%>

    Author: ${doc.author}

    <%}%>

    Content-Type: ${doc.contentType}

    Description: ${doc.detail}

    <%if(isNotEmpty(doc.requestHeaders)){%>

    Request-headers:

    <%for(header in doc.requestHeaders){%><%}%>
    HeaderValueTypeRequiredDescription

    ${header.name}

    ${header.type}

    ${header.required}

    ${header.desc}

    <%}%><%if(isNotEmpty(doc.pathParams)){%>

    Path-parameters:

    <%for(param in doc.pathParams){%><%}%>
    ParameterValueTypeRequiredDescription

    ${param.field}

    ${param.type}

    ${param.required}

    ${param.desc}

    <%}%><%if(isNotEmpty(doc.queryParams)){%>

    Query-parameters:

    <%for(param in doc.queryParams){%><%}%>
    ParameterValueTypeRequiredDescription

    ${param.field}

    <%if(param.type=="file"){%><%}else{%><%}%>

    ${param.type}

    ${param.required}

    ${param.desc}

    <%}%><%if(isNotEmpty(doc.requestParams)){%>

    Body-parameters:

    <%for(param in doc.requestParams){%><%}%>
    ParameterTypeRequiredDescription

    ${param.field}

    ${param.type}

    ${param.required}

    ${param.desc}

    <%}%><%if(isNotEmpty(doc.requestExample.jsonBody)&&isRequestExample){%>

    Request-body:

    <%}%><%if(isNotEmpty(doc.responseParams)){%>

    Response-fields:

    <%for(param in doc.responseParams){%><%}%>
    FieldTypeDescriptionSince

    ${param.field}

    ${param.type}

    ${param.desc}

    ${param.version}

    <%}%>

    <%if(isNotEmpty(doc.responseUsage)&&isResponseExample){%>

    Response-example:

    ${doc.responseUsage}
    <%}%><%if(isNotEmpty(doc.requestUsage)&&isRequestExample){%>

    Curl-example:

    ${doc.requestUsage}
    <%}%>
    <%}%>
    <%}%><%if(isNotEmpty(errorCodeList)){%>

    ${apiDocList.~size+1}. ${errorListTitle}

    <%for(error in errorCodeList){%><%}%>
    Error codeDescription

    ${error.value}

    ${error.desc}

    <%}%><%if(isNotEmpty(dictList)){%>

    ${dictListOrder}. ${dictListTitle}

    <% for(dict in dictList){ %>

    ${dictListOrder}.${dict.order}. ${dict.title}

    <%for(dataDict in dict.dataDictList){%><%}%>
    CodeTypeDescription

    ${dataDict.value}

    ${dataDict.type}

    ${dataDict.desc}

    <%}%>
    <%}%>
    Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github
    + + + + + + + <%if(isNotEmpty(projectName)){%>${projectName}<%}else{%>API Reference<%}%> + + + + + + +
    <%if(isNotEmpty(revisionLogList)){%> +
    +
    + + + + + + + + + + + + + + + + + + <%for(revisionLog in revisionLogList){%> + + + + + + + + <%}%> + +
    VersionUpdate TimeStatusAuthorDescription

    ${revisionLog.version}

    ${revisionLog.revisionTime}

    +

    ${revisionLog.status}

    ${revisionLog.author}

    ${revisionLog.remarks}

    +
    +
    + <%}%><%for(api in apiDocList){%> +

    ${api.order}. ${api.desc} +

    +
    <%for(doc in api.list){%> +

    <%if(doc.deprecated){%>${api.order}.${doc.order}. ${doc.desc}<%}else{%>${api.order}.${doc.order}. ${doc.desc}<%}%> +

    + +

    Type: ${doc.type} +

    + <%if(isNotEmpty(doc.author)){%> +

    Author: ${doc.author}

    + <%}%> +

    + Content-Type: ${doc.contentType}

    +

    Description: ${doc.detail}

    + <%if(isNotEmpty(doc.requestHeaders)){%> +

    Request-headers:

    + + + + + + + + + + + + + + + + + + + + <%for(header in doc.requestHeaders){%> + + + + + + + + + <%}%> + +
    +
    +
    HeaderValueTypeRequiredDescription
    +
    +

    ${header.name}

    +

    ${header.type}

    ${header.required}

    ${header.desc}

    + <%}%><%if(isNotEmpty(doc.pathParams)){%> +

    Path-parameters:

    + + + + + + + + + + + + + + + + + + + + <%for(param in doc.pathParams){%> + + + + + + + + + <%}%> + +
    +
    +
    ParameterValueTypeRequiredDescription
    +
    +

    ${param.field}

    +

    ${param.type}

    ${param.required}

    ${param.desc}

    + <%}%><%if(isNotEmpty(doc.queryParams)){%> +

    Query-parameters:

    + + + + + + + + + + + + + + + + + + + + <%for(param in doc.queryParams){%> + + + + + + + + + <%}%> + +
    +
    +
    ParameterValueTypeRequiredDescription
    +
    +

    ${param.field}

    + <%if(param.type=="file"){%><%}else{%><%}%>

    ${param.type}

    ${param.required}

    ${param.desc}

    + <%}%><%if(isNotEmpty(doc.requestParams)){%> +

    Body-parameters:

    + + + + + + + + + + + + + + + + + <%for(param in doc.requestParams){%> + + + + + + + <%}%> + +
    ParameterTypeRequiredDescription

    ${param.field}

    ${param.type}

    ${param.required}

    ${param.desc}

    + <%}%> + <%if(isNotEmpty(doc.requestExample.jsonBody)&&isRequestExample){%> +

    Request-body:

    +
    +
    +
    +
    + <%}%> + <%if(isNotEmpty(doc.responseParams)){%> +

    Response-fields:

    + + + + + + + + + + + + + + + + <%for(param in doc.responseParams){%> + + + + + + + <%}%> + +
    FieldTypeDescriptionSince

    ${param.field}

    ${param.type}

    ${param.desc}

    ${param.version}

    + <%}%> +
    +

    + +

    +
    + <%if(isNotEmpty(doc.responseUsage)&&isResponseExample){%> +

    Response-example:

    +
    +
    +
    ${doc.responseUsage}
    +
    +
    + <%}%> + <%if(isNotEmpty(doc.requestUsage)&&isRequestExample){%> +

    Curl-example:

    +
    +
    +
    ${doc.requestUsage}
    +
    +
    + <%}%> +
    + <%}%> +
    +
    + <%}%><%if(isNotEmpty(errorCodeList)){%> +

    ${apiDocList.~size+1}. ${errorListTitle} +

    +
    + + + + + + + + + + + + <%for(error in errorCodeList){%> + + + + + <%}%> + +
    Error codeDescription

    ${error.value}

    ${error.desc}

    +
    +
    + <%}%><%if(isNotEmpty(dictList)){%> +

    ${dictListOrder}. ${dictListTitle} +

    +
    <% for(dict in dictList){ %> +

    ${dictListOrder}.${dict.order}. ${dict.title} +

    + + + + + + + + + + + + + + <%for(dataDict in dict.dataDictList){%> + + + + + + <%}%> + +
    CodeTypeDescription

    ${dataDict.value}

    ${dataDict.type}

    ${dataDict.desc}

    +
    + <%}%> +
    +
    + <%}%> +
    Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github +
    +