diff --git a/src/main/java/com/ly/doc/builder/AdocDocBuilder.java b/src/main/java/com/ly/doc/builder/AdocDocBuilder.java index 4c292a1d..0930912c 100644 --- a/src/main/java/com/ly/doc/builder/AdocDocBuilder.java +++ b/src/main/java/com/ly/doc/builder/AdocDocBuilder.java @@ -67,7 +67,7 @@ public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectB Objects.requireNonNull(docBuildTemplate, "doc build template is null"); List apiDocList = docBuildTemplate.getApiData(configBuilder).getApiDatas(); if (config.isAllInOne()) { - String docName = builderTemplate.allInOneDocName(config, INDEX_DOC, ".adoc"); + String docName = builderTemplate.allInOneDocName(config, INDEX_DOC, DocGlobalConstants.ASCIIDOC_EXTENSION); apiDocList = docBuildTemplate.handleApiGroup(apiDocList, config); builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, DocGlobalConstants.ALL_IN_ONE_ADOC_TPL, docName); diff --git a/src/main/java/com/ly/doc/builder/DocBuilderTemplate.java b/src/main/java/com/ly/doc/builder/DocBuilderTemplate.java index 534443da..f90f3ea4 100644 --- a/src/main/java/com/ly/doc/builder/DocBuilderTemplate.java +++ b/src/main/java/com/ly/doc/builder/DocBuilderTemplate.java @@ -20,7 +20,10 @@ */ package com.ly.doc.builder; -import com.ly.doc.constants.*; +import com.ly.doc.constants.DocGlobalConstants; +import com.ly.doc.constants.HighlightStyle; +import com.ly.doc.constants.TemplateVariable; +import com.ly.doc.constants.TornaConstants; import com.ly.doc.factory.BuildTemplateFactory; import com.ly.doc.model.*; import com.ly.doc.template.IDocBuildTemplate; @@ -43,7 +46,7 @@ * * @author yu 2019/9/26. */ -public class DocBuilderTemplate implements IBaseDocBuilderTemplate { +public class DocBuilderTemplate implements IBaseDocBuilderTemplate { /** * get all api data @@ -73,7 +76,7 @@ public ApiAllData getApiData(ApiConfig config, JavaProjectBuilder javaProjectBui public void buildApiDoc(List apiDocList, ApiConfig config, String template, String fileExtension) { FileUtil.mkdirs(config.getOutPath()); for (ApiDoc doc : apiDocList) { - Template mapper = buildApiDocTemplate(doc, config, template); + Template mapper = this.buildApiDocTemplate(doc, config, template); FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + doc.getName() + fileExtension); } @@ -106,16 +109,11 @@ public Template buildApiDocTemplate(ApiDoc doc, ApiConfig config, String templat */ public void buildAllInOne(List apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) { - buildDoc(apiDocList, config, javaProjectBuilder, template, outPutFileName, null, null); - } - - public void buildWebSocket(List webSocketDocList, ApiConfig config, - JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) { - buildWebSocketDoc(webSocketDocList, config, javaProjectBuilder, template, outPutFileName, null); + this.buildDoc(apiDocList, config, javaProjectBuilder, template, outPutFileName, null, null); } /** - * get render doc template + * get render doc template. * @param apiDocList list data of Api doc * @param config api config * @param javaProjectBuilder JavaProjectBuilder @@ -145,9 +143,9 @@ public Template buildAllRenderDocTemplate(List apiDocList, ApiConfig con tpl.binding(TemplateVariable.RESPONSE_EXAMPLE.getVariable(), config.isResponseExample()); tpl.binding(TemplateVariable.DISPLAY_REQUEST_PARAMS.getVariable(), config.isRequestParamsTable()); tpl.binding(TemplateVariable.DISPLAY_RESPONSE_PARAMS.getVariable(), config.isResponseParamsTable()); - setCssCDN(config, tpl); + this.setCssCDN(config, tpl); - setDirectoryLanguageVariable(config, tpl); + this.setDirectoryLanguageVariable(config, tpl); List apiDocDictList = DocUtil.buildDictionary(config, javaProjectBuilder); tpl.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList); @@ -189,34 +187,7 @@ public Template buildAllRenderDocTemplate(List apiDocList, ApiConfig con } /** - * get render doc template - * @param webSocketDocList list data of webSocket doc - * @param config api config - * @param javaProjectBuilder JavaProjectBuilder - * @param template template - * @param index index html - * @return Template - */ - public Template buildAllWebSocketDocTemplate(List webSocketDocList, ApiConfig config, - JavaProjectBuilder javaProjectBuilder, String template, String index) { - String strTime = DateTimeUtil.long2Str(NOW, DateTimeUtil.DATE_FORMAT_SECOND); - Template tpl = BeetlTemplateUtil.getByName(template); - String style = config.getStyle(); - tpl.binding(TemplateVariable.VERSION_LIST.getVariable(), config.getRevisionLogs()); - tpl.binding(TemplateVariable.STYLE.getVariable(), style); - tpl.binding(TemplateVariable.HIGH_LIGHT_CSS_LINK.getVariable(), config.getHighlightStyleLink()); - tpl.binding(TemplateVariable.BACKGROUND.getVariable(), HighlightStyle.getBackgroundColor(style)); - tpl.binding(TemplateVariable.WEBSOCKET_DOC_LIST.getVariable(), webSocketDocList); - tpl.binding(TemplateVariable.LANGUAGE.getVariable(), config.getLanguage()); - tpl.binding(TemplateVariable.VERSION.getVariable(), NOW); - tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime); - tpl.binding(TemplateVariable.PROJECT_NAME.getVariable(), config.getProjectName()); - setCssCDN(config, tpl); - return tpl; - } - - /** - * Merge all api doc into one document + * Merge all api doc into one document. * @param apiDocList list data of Api doc * @param config api config * @param javaProjectBuilder JavaProjectBuilder @@ -229,18 +200,17 @@ public void buildDoc(List apiDocList, ApiConfig config, JavaProjectBuild String template, String outPutFileName, ApiDoc apiDoc, String index) { String outPath = config.getOutPath(); FileUtil.mkdirs(outPath); - Template tpl = buildAllRenderDocTemplate(apiDocList, config, javaProjectBuilder, template, apiDoc, index); - FileUtil.nioWriteFile(tpl.render(), outPath + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); - } - - public void buildWebSocketDoc(List webSocketDocList, ApiConfig config, - JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName, String index) { - String outPath = config.getOutPath(); - FileUtil.mkdirs(outPath); - Template tpl = buildAllWebSocketDocTemplate(webSocketDocList, config, javaProjectBuilder, template, index); + Template tpl = this.buildAllRenderDocTemplate(apiDocList, config, javaProjectBuilder, template, apiDoc, index); FileUtil.nioWriteFile(tpl.render(), outPath + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); } + /** + * build search js. + * @param config api config + * @param javaProjectBuilder JavaProjectBuilder + * @param apiDocList list data of Api doc + * @param template template + */ public void buildSearchJs(ApiConfig config, JavaProjectBuilder javaProjectBuilder, List apiDocList, String template) { List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); @@ -253,7 +223,7 @@ public void buildSearchJs(ApiConfig config, JavaProjectBuilder javaProjectBuilde } boolean isOnlyDefaultGroup = apiDocList.size() == 1; - Map titleMap = setDirectoryLanguageVariable(config, tpl); + Map titleMap = this.setDirectoryLanguageVariable(config, tpl); // set error code if (CollectionUtil.isNotEmpty(errorCodeList)) { ApiDoc apiDoc1 = new ApiDoc(); @@ -333,38 +303,7 @@ public void buildSearchJs(ApiConfig config, JavaProjectBuilder javaProjectBuilde } /** - * build error_code adoc - * @param config api config - * @param template template - * @param outPutFileName output file - * @param javaProjectBuilder javaProjectBuilder - */ - public void buildErrorCodeDoc(ApiConfig config, String template, String outPutFileName, - JavaProjectBuilder javaProjectBuilder) { - Template tpl = buildErrorCodeDocTemplate(config, template, javaProjectBuilder); - FileUtil.nioWriteFile(tpl.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); - } - - /** - * build errorCode adoc template - * @param config api config - * @param template template - * @param javaProjectBuilder javaProjectBuilder - * @return template - */ - public Template buildErrorCodeDocTemplate(ApiConfig config, String template, - JavaProjectBuilder javaProjectBuilder) { - List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); - String strTime = DateTimeUtil.long2Str(NOW, DateTimeUtil.DATE_FORMAT_SECOND); - Template tpl = BeetlTemplateUtil.getByName(template); - setCssCDN(config, tpl); - tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime); - tpl.binding(TemplateVariable.LIST.getVariable(), errorCodeList); - return tpl; - } - - /** - * build error_code html + * build error_code html. * @param config api config * @param javaProjectBuilder javaProjectBuilder * @param apiDocList list data of Api doc @@ -388,7 +327,7 @@ public void buildErrorCodeDoc(ApiConfig config, JavaProjectBuilder javaProjectBu errorTemplate.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 2); } // set css cdn - setCssCDN(config, errorTemplate); + this.setCssCDN(config, errorTemplate); List apiDocDictList = DocUtil.buildDictionary(config, javaProjectBuilder); errorTemplate.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime); errorTemplate.binding(TemplateVariable.VERSION.getVariable(), NOW); @@ -404,7 +343,7 @@ public void buildErrorCodeDoc(ApiConfig config, JavaProjectBuilder javaProjectBu } /** - * build common_data doc + * build common_data doc. * @param config api config * @param javaProjectBuilder JavaProjectBuilder * @param apiDocList list data of Api doc @@ -423,13 +362,7 @@ public void buildDirectoryDataDoc(ApiConfig config, JavaProjectBuilder javaProje mapper.binding(TemplateVariable.STYLE.getVariable(), style); List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); // set css cdn - setCssCDN(config, mapper); - if (DocLanguage.CHINESE.equals(config.getLanguage())) { - mapper.binding(TemplateVariable.CSS_CND.getVariable(), DocGlobalConstants.CSS_CDN_CH); - } - else { - mapper.binding(TemplateVariable.CSS_CND.getVariable(), DocGlobalConstants.CSS_CDN); - } + this.setCssCDN(config, mapper); if (CollectionUtil.isNotEmpty(errorCodeList)) { mapper.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 2); } @@ -443,14 +376,14 @@ public void buildDirectoryDataDoc(ApiConfig config, JavaProjectBuilder javaProje 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); + this.setDirectoryLanguageVariable(config, mapper); mapper.binding(TemplateVariable.DICT_LIST.getVariable(), directoryList); FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); } /** - * build common_data doc + * build common_data doc. * @param config api config * @param javaProjectBuilder JavaProjectBuilder * @param template template @@ -464,7 +397,7 @@ public void buildDirectoryDataDoc(ApiConfig config, JavaProjectBuilder javaProje } /** - * build common_data doc Template + * build common_data doc Template. * @param config api config * @param javaProjectBuilder JavaProjectBuilder * @param template template @@ -474,15 +407,21 @@ public Template buildDirectoryDataDocTemplate(ApiConfig config, JavaProjectBuild String template) { List directoryList = DocUtil.buildDictionary(config, javaProjectBuilder); Template mapper = BeetlTemplateUtil.getByName(template); - setDirectoryLanguageVariable(config, mapper); + this.setDirectoryLanguageVariable(config, mapper); // set css cdn - setCssCDN(config, mapper); + this.setCssCDN(config, mapper); String strTime = DateTimeUtil.long2Str(NOW, DateTimeUtil.DATE_FORMAT_SECOND); mapper.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime); mapper.binding(TemplateVariable.DICT_LIST.getVariable(), directoryList); return mapper; } + /** + * get api data. + * @param config api config + * @param javaProjectBuilder JavaProjectBuilder + * @return ApiData list + */ private List listOfApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { this.checkAndInitForGetApiData(config); config.setMd5EncryptedHtmlName(true); diff --git a/src/main/java/com/ly/doc/builder/IBaseDocBuilderTemplate.java b/src/main/java/com/ly/doc/builder/IBaseDocBuilderTemplate.java index fb3fa6ab..bab147b4 100644 --- a/src/main/java/com/ly/doc/builder/IBaseDocBuilderTemplate.java +++ b/src/main/java/com/ly/doc/builder/IBaseDocBuilderTemplate.java @@ -24,10 +24,9 @@ import com.ly.doc.constants.DocLanguage; import com.ly.doc.constants.FrameworkEnum; import com.ly.doc.constants.TemplateVariable; -import com.ly.doc.model.ApiConfig; -import com.ly.doc.model.ApiDocDict; -import com.ly.doc.model.ApiErrorCode; -import com.ly.doc.model.RevisionLog; +import com.ly.doc.factory.BuildTemplateFactory; +import com.ly.doc.model.*; +import com.ly.doc.template.IDocBuildTemplate; import com.ly.doc.utils.BeetlTemplateUtil; import com.ly.doc.utils.DocUtil; import com.power.common.util.CollectionUtil; @@ -48,19 +47,44 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.logging.Logger; /** * doc builder template interface. * * @author yu 2020/5/16. */ -public interface IBaseDocBuilderTemplate { +public interface IBaseDocBuilderTemplate { + + /** + * Logger for the class. + */ + Logger log = Logger.getLogger(IBaseDocBuilderTemplate.class.getName()); /** * now currentTimeMillis. */ long NOW = System.currentTimeMillis(); + /** + * get all doc api data + * @param config ApiConfig + * @param javaProjectBuilder JavaProjectBuilder + * @return ApiAllData + */ + default List getApiDoc(boolean adoc, boolean showJavaType, boolean paramsDataToTree, ApiConfig config, + JavaProjectBuilder javaProjectBuilder) { + config.setAdoc(adoc); + config.setShowJavaType(showJavaType); + config.setParamsDataToTree(paramsDataToTree); + this.checkAndInit(config, Boolean.TRUE); + ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); + IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework(), + config.getClassLoader()); + Objects.requireNonNull(docBuildTemplate, "doc build template is null"); + return docBuildTemplate.getApiData(configBuilder).getApiDatas(); + } + /** * check condition and init * @param config Api config @@ -193,8 +217,8 @@ default void bindingCommonVariable(ApiConfig config, JavaProjectBuilder javaProj if (CollectionUtil.isNotEmpty(apiDocDictList)) { template.binding(TemplateVariable.DICT_ORDER.getVariable(), ++codeIndex); } - setDirectoryLanguageVariable(config, template); - setCssCDN(config, template); + this.setDirectoryLanguageVariable(config, template); + this.setCssCDN(config, template); } /** @@ -206,7 +230,7 @@ default void bindingCommonVariable(ApiConfig config, JavaProjectBuilder javaProj */ default String allInOneDocName(ApiConfig apiConfig, String fileName, String suffix) { String allInOneName = apiConfig.getAllInOneDocFileName(); - if (StringUtils.isNotEmpty(apiConfig.getAllInOneDocFileName())) { + if (StringUtils.isNotEmpty(allInOneName)) { if (allInOneName.endsWith(suffix)) { return allInOneName; } @@ -269,8 +293,39 @@ static void copyJarFile(String source, String target) { bufferedWriter.close(); } catch (IOException e) { - e.printStackTrace(); + log.warning("copy jar file error:" + e.getMessage()); } } + /** + * build error_code adoc. + * @param config api config + * @param template template + * @param outPutFileName output file + * @param javaProjectBuilder javaProjectBuilder + */ + default void buildErrorCodeDoc(ApiConfig config, String template, String outPutFileName, + JavaProjectBuilder javaProjectBuilder) { + Template tpl = this.buildErrorCodeDocTemplate(config, template, javaProjectBuilder); + FileUtil.nioWriteFile(tpl.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); + } + + /** + * build errorCode adoc template. + * @param config api config + * @param template template + * @param javaProjectBuilder javaProjectBuilder + * @return template + */ + default Template buildErrorCodeDocTemplate(ApiConfig config, String template, + JavaProjectBuilder javaProjectBuilder) { + List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); + String strTime = DateTimeUtil.long2Str(NOW, DateTimeUtil.DATE_FORMAT_SECOND); + Template tpl = BeetlTemplateUtil.getByName(template); + this.setCssCDN(config, tpl); + tpl.binding(TemplateVariable.CREATE_TIME.getVariable(), strTime); + tpl.binding(TemplateVariable.LIST.getVariable(), errorCodeList); + return tpl; + } + } diff --git a/src/main/java/com/ly/doc/builder/IRpcDocBuilderTemplate.java b/src/main/java/com/ly/doc/builder/IRpcDocBuilderTemplate.java index 863d99ca..81d6ceef 100644 --- a/src/main/java/com/ly/doc/builder/IRpcDocBuilderTemplate.java +++ b/src/main/java/com/ly/doc/builder/IRpcDocBuilderTemplate.java @@ -23,11 +23,11 @@ import com.ly.doc.constants.DocGlobalConstants; import com.ly.doc.constants.TemplateVariable; import com.ly.doc.factory.BuildTemplateFactory; +import com.ly.doc.model.AbstractRpcApiDoc; import com.ly.doc.model.ApiConfig; import com.ly.doc.model.ApiDocDict; import com.ly.doc.model.ApiErrorCode; import com.ly.doc.model.rpc.RpcApiAllData; -import com.ly.doc.model.rpc.RpcApiDoc; import com.ly.doc.template.IDocBuildTemplate; import com.ly.doc.utils.BeetlTemplateUtil; import com.ly.doc.utils.DocUtil; @@ -41,13 +41,26 @@ import java.util.Map; import java.util.Objects; -public interface IRpcDocBuilderTemplate extends IBaseDocBuilderTemplate { +/** + * rpc api doc builder template. + * + * @param AbstractRpcApiDoc + * @author linwumingshi + * @since 3.0.7 + */ +public interface IRpcDocBuilderTemplate> extends IBaseDocBuilderTemplate { /** * Add dependency title */ String DEPENDENCY_TITLE = "Add dependency"; + /** + * Create empty api doc. + * @return empty api doc + */ + T createEmptyApiDoc(); + /** * Generate api documentation for all controllers. * @param apiDocList list of api doc @@ -55,9 +68,9 @@ public interface IRpcDocBuilderTemplate extends IBaseDocBuilderTemplate { * @param template template * @param fileExtension file extension */ - default void buildApiDoc(List apiDocList, ApiConfig config, String template, String fileExtension) { + default void buildApiDoc(List apiDocList, ApiConfig config, String template, String fileExtension) { FileUtil.mkdirs(config.getOutPath()); - for (RpcApiDoc rpcDoc : apiDocList) { + for (T rpcDoc : apiDocList) { Template mapper = BeetlTemplateUtil.getByName(template); mapper.binding(TemplateVariable.DESC.getVariable(), rpcDoc.getDesc()); mapper.binding(TemplateVariable.NAME.getVariable(), rpcDoc.getName()); @@ -77,7 +90,7 @@ default void buildApiDoc(List apiDocList, ApiConfig config, String te * @param rpcDoc api doc * @param fileExtension file extension */ - default void writeApiDocFile(Template mapper, ApiConfig config, RpcApiDoc rpcDoc, String fileExtension) { + default void writeApiDocFile(Template mapper, ApiConfig config, T rpcDoc, String fileExtension) { FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + rpcDoc.getShortName() + fileExtension); } @@ -90,7 +103,7 @@ default void writeApiDocFile(Template mapper, ApiConfig config, RpcApiDoc rpcDoc * @param template template * @param outPutFileName output file */ - default void buildAllInOne(List apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, + default void buildAllInOne(List apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) { String outPath = config.getOutPath(); String rpcConfig = config.getRpcConsumerConfig(); @@ -104,7 +117,7 @@ default void buildAllInOne(List apiDocList, ApiConfig config, JavaPro tpl.binding(TemplateVariable.DEPENDENCY_LIST.getVariable(), config.getRpcApiDependencies()); tpl.binding(TemplateVariable.RPC_CONSUMER_CONFIG.getVariable(), rpcConfigConfigContent); // binding common variable - bindingCommonVariable(config, javaProjectBuilder, tpl, apiDocList.isEmpty()); + this.bindingCommonVariable(config, javaProjectBuilder, tpl, apiDocList.isEmpty()); FileUtil.nioWriteFile(tpl.render(), outPath + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); } @@ -116,25 +129,25 @@ default void buildAllInOne(List apiDocList, ApiConfig config, JavaPro * @param template template * @param outPutFileName output file */ - default void buildSearchJs(List apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, + default void buildSearchJs(List apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) { List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); Template tpl = BeetlTemplateUtil.getByName(template); // directory tree - List apiDocs = new ArrayList<>(); - RpcApiDoc apiDoc = new RpcApiDoc(); + List apiDocs = new ArrayList<>(); + T apiDoc = this.createEmptyApiDoc(); apiDoc.setAlias(DEPENDENCY_TITLE); apiDoc.setOrder(1); apiDoc.setDesc(DEPENDENCY_TITLE); apiDoc.setList(new ArrayList<>(0)); apiDocs.add(apiDoc); - for (RpcApiDoc apiDoc1 : apiDocList) { + for (T apiDoc1 : apiDocList) { apiDoc1.setOrder(apiDocs.size() + 1); apiDocs.add(apiDoc1); } - Map titleMap = setDirectoryLanguageVariable(config, tpl); + Map titleMap = this.setDirectoryLanguageVariable(config, tpl); if (CollectionUtil.isNotEmpty(errorCodeList)) { - RpcApiDoc apiDoc1 = new RpcApiDoc(); + T apiDoc1 = this.createEmptyApiDoc(); apiDoc1.setOrder(apiDocs.size() + 1); apiDoc1.setDesc(titleMap.get(TemplateVariable.ERROR_LIST_TITLE.getVariable())); apiDoc1.setList(new ArrayList<>(0)); @@ -148,34 +161,18 @@ default void buildSearchJs(List apiDocList, ApiConfig config, JavaPro FileUtil.nioWriteFile(tpl.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); } - /** - * build error_code adoc. - * @param config api config - * @param template template - * @param outPutFileName output file - * @param javaProjectBuilder javaProjectBuilder - */ - default void buildErrorCodeDoc(ApiConfig config, String template, String outPutFileName, - JavaProjectBuilder javaProjectBuilder) { - List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); - Template mapper = BeetlTemplateUtil.getByName(template); - mapper.binding(TemplateVariable.LIST.getVariable(), errorCodeList); - FileUtil.nioWriteFile(mapper.render(), - config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); - } - /** * get all api data * @param config ApiConfig * @param javaProjectBuilder JavaProjectBuilder * @return ApiAllData */ - default RpcApiAllData getApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { - RpcApiAllData apiAllData = new RpcApiAllData(); + default RpcApiAllData getApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { + RpcApiAllData apiAllData = new RpcApiAllData<>(); apiAllData.setProjectId(DocUtil.generateId(config.getProjectName())); apiAllData.setLanguage(config.getLanguage().getCode()); apiAllData.setProjectName(config.getProjectName()); - apiAllData.setApiDocList(listOfApiData(config, javaProjectBuilder)); + apiAllData.setApiDocList(this.listOfApiData(config, javaProjectBuilder)); apiAllData.setErrorCodeList(DocUtil.errorCodeDictToList(config, javaProjectBuilder)); apiAllData.setRevisionLogs(config.getRevisionLogs()); apiAllData.setApiDocDictList(DocUtil.buildDictionary(config, javaProjectBuilder)); @@ -189,26 +186,11 @@ default RpcApiAllData getApiData(ApiConfig config, JavaProjectBuilder javaProjec * @param javaProjectBuilder JavaProjectBuilder * @return ApiAllData */ - default List listOfApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { + default List listOfApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { this.checkAndInitForGetApiData(config); config.setMd5EncryptedHtmlName(true); ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); - IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework(), - config.getClassLoader()); - Objects.requireNonNull(docBuildTemplate, "doc build template is null"); - return docBuildTemplate.getApiData(configBuilder).getApiDatas(); - } - - /** - * get all api data. - * @param config ApiConfig - * @param javaProjectBuilder JavaProjectBuilder - * @return ApiAllData - */ - default List getRpcApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { - config.setShowJavaType(true); - ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); - IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework(), + IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework(), config.getClassLoader()); Objects.requireNonNull(docBuildTemplate, "doc build template is null"); return docBuildTemplate.getApiData(configBuilder).getApiDatas(); diff --git a/src/main/java/com/ly/doc/builder/grpc/GrpcAsciidocBuilder.java b/src/main/java/com/ly/doc/builder/grpc/GrpcAsciidocBuilder.java index f6168c74..23f070c6 100644 --- a/src/main/java/com/ly/doc/builder/grpc/GrpcAsciidocBuilder.java +++ b/src/main/java/com/ly/doc/builder/grpc/GrpcAsciidocBuilder.java @@ -23,7 +23,7 @@ import com.ly.doc.constants.DocGlobalConstants; import com.ly.doc.helper.JavaProjectBuilderHelper; import com.ly.doc.model.ApiConfig; -import com.ly.doc.model.rpc.RpcApiDoc; +import com.ly.doc.model.grpc.GrpcApiDoc; import com.thoughtworks.qdox.JavaProjectBuilder; import java.util.List; @@ -36,8 +36,14 @@ */ public class GrpcAsciidocBuilder { - private static final String API_EXTENSION = "gRpcApi.adoc"; + /** + * grpc api extension. + */ + private static final String API_EXTENSION = "GRpcApi.adoc"; + /** + * grpc index extension. + */ private static final String INDEX_DOC = "grpc-index.adoc"; /** @@ -55,12 +61,11 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { - config.setAdoc(true); GrpcDocBuilderTemplate grpcDocBuilderTemplate = new GrpcDocBuilderTemplate(); - grpcDocBuilderTemplate.checkAndInit(config, Boolean.TRUE); - List apiDocList = grpcDocBuilderTemplate.getRpcApiDoc(config, javaProjectBuilder); + List apiDocList = grpcDocBuilderTemplate.getApiDoc(true, true, false, config, javaProjectBuilder); if (config.isAllInOne()) { - String docName = grpcDocBuilderTemplate.allInOneDocName(config, INDEX_DOC, ".adoc"); + String docName = grpcDocBuilderTemplate.allInOneDocName(config, INDEX_DOC, + DocGlobalConstants.ASCIIDOC_EXTENSION); grpcDocBuilderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, DocGlobalConstants.GRPC_ALL_IN_ONE_ADOC_TPL, docName); } diff --git a/src/main/java/com/ly/doc/builder/grpc/GrpcDocBuilderTemplate.java b/src/main/java/com/ly/doc/builder/grpc/GrpcDocBuilderTemplate.java index 45dd4b9f..61bcbe79 100644 --- a/src/main/java/com/ly/doc/builder/grpc/GrpcDocBuilderTemplate.java +++ b/src/main/java/com/ly/doc/builder/grpc/GrpcDocBuilderTemplate.java @@ -28,7 +28,7 @@ import com.ly.doc.model.ApiConfig; import com.ly.doc.model.ApiDocDict; import com.ly.doc.model.ApiErrorCode; -import com.ly.doc.model.rpc.RpcApiDoc; +import com.ly.doc.model.grpc.GrpcApiDoc; import com.ly.doc.utils.BeetlTemplateUtil; import com.ly.doc.utils.DocUtil; import com.power.common.util.CollectionUtil; @@ -47,7 +47,7 @@ * @author linwumingshi * @since 3.0.7 */ -public class GrpcDocBuilderTemplate implements IRpcDocBuilderTemplate { +public class GrpcDocBuilderTemplate implements IRpcDocBuilderTemplate { @Override public void checkAndInit(ApiConfig config, boolean checkOutPath) { @@ -59,25 +59,30 @@ public void checkAndInit(ApiConfig config, boolean checkOutPath) { } @Override - public void writeApiDocFile(Template mapper, ApiConfig config, RpcApiDoc rpcDoc, String fileExtension) { + public GrpcApiDoc createEmptyApiDoc() { + return new GrpcApiDoc(); + } + + @Override + public void writeApiDocFile(Template mapper, ApiConfig config, GrpcApiDoc rpcDoc, String fileExtension) { FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + rpcDoc.getName() + fileExtension); } @Override - public void buildSearchJs(List apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, + public void buildSearchJs(List apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) { List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); Template tpl = BeetlTemplateUtil.getByName(template); - // directory tree - List apiDocs = new ArrayList<>(); - for (RpcApiDoc apiDoc1 : apiDocList) { + // add order + List apiDocs = new ArrayList<>(); + for (GrpcApiDoc apiDoc1 : apiDocList) { apiDoc1.setOrder(apiDocs.size()); apiDocs.add(apiDoc1); } - Map titleMap = setDirectoryLanguageVariable(config, tpl); + Map titleMap = this.setDirectoryLanguageVariable(config, tpl); if (CollectionUtil.isNotEmpty(errorCodeList)) { - RpcApiDoc apiDoc1 = new RpcApiDoc(); + GrpcApiDoc apiDoc1 = new GrpcApiDoc(); apiDoc1.setOrder(apiDocs.size()); apiDoc1.setDesc(titleMap.get(TemplateVariable.ERROR_LIST_TITLE.getVariable())); apiDoc1.setList(new ArrayList<>(0)); diff --git a/src/main/java/com/ly/doc/builder/grpc/GrpcHtmlBuilder.java b/src/main/java/com/ly/doc/builder/grpc/GrpcHtmlBuilder.java index c9db53f4..cefea0aa 100644 --- a/src/main/java/com/ly/doc/builder/grpc/GrpcHtmlBuilder.java +++ b/src/main/java/com/ly/doc/builder/grpc/GrpcHtmlBuilder.java @@ -23,7 +23,7 @@ import com.ly.doc.constants.DocGlobalConstants; import com.ly.doc.helper.JavaProjectBuilderHelper; import com.ly.doc.model.ApiConfig; -import com.ly.doc.model.rpc.RpcApiDoc; +import com.ly.doc.model.grpc.GrpcApiDoc; import com.thoughtworks.qdox.JavaProjectBuilder; import java.util.List; @@ -36,6 +36,11 @@ */ public class GrpcHtmlBuilder { + /** + * index.html + */ + private final static String INDEX_HTML = "grpc-index.html"; + /** * build grpc api * @param config config @@ -51,15 +56,13 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig apiConfig, JavaProjectBuilder javaProjectBuilder) { - apiConfig.setAdoc(Boolean.FALSE); - GrpcDocBuilderTemplate builderTemplate = new GrpcDocBuilderTemplate(); - builderTemplate.checkAndInit(apiConfig, Boolean.TRUE); - List apiDocList = builderTemplate.getRpcApiDoc(apiConfig, javaProjectBuilder); - builderTemplate.copyJQueryAndCss(apiConfig); - String indexHtml = "grpc-index.html"; - builderTemplate.buildAllInOne(apiDocList, apiConfig, javaProjectBuilder, - DocGlobalConstants.GRPC_ALL_IN_ONE_HTML_TPL, indexHtml); - builderTemplate.buildSearchJs(apiDocList, apiConfig, javaProjectBuilder, + GrpcDocBuilderTemplate grpcDocBuilderTemplate = new GrpcDocBuilderTemplate(); + List apiDocList = grpcDocBuilderTemplate.getApiDoc(false, true, false, apiConfig, + javaProjectBuilder); + grpcDocBuilderTemplate.copyJQueryAndCss(apiConfig); + grpcDocBuilderTemplate.buildAllInOne(apiDocList, apiConfig, javaProjectBuilder, + DocGlobalConstants.GRPC_ALL_IN_ONE_HTML_TPL, INDEX_HTML); + grpcDocBuilderTemplate.buildSearchJs(apiDocList, apiConfig, javaProjectBuilder, DocGlobalConstants.GRPC_ALL_IN_ONE_SEARCH_TPL, DocGlobalConstants.SEARCH_JS_OUT); } diff --git a/src/main/java/com/ly/doc/builder/grpc/GrpcMarkdownBuilder.java b/src/main/java/com/ly/doc/builder/grpc/GrpcMarkdownBuilder.java index ef657518..374a8e9c 100644 --- a/src/main/java/com/ly/doc/builder/grpc/GrpcMarkdownBuilder.java +++ b/src/main/java/com/ly/doc/builder/grpc/GrpcMarkdownBuilder.java @@ -24,7 +24,7 @@ import com.ly.doc.constants.DocGlobalConstants; import com.ly.doc.helper.JavaProjectBuilderHelper; import com.ly.doc.model.ApiConfig; -import com.ly.doc.model.rpc.RpcApiDoc; +import com.ly.doc.model.grpc.GrpcApiDoc; import com.power.common.util.DateTimeUtil; import com.thoughtworks.qdox.JavaProjectBuilder; @@ -53,10 +53,9 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig apiConfig, JavaProjectBuilder javaProjectBuilder) { - apiConfig.setAdoc(Boolean.FALSE); GrpcDocBuilderTemplate grpcDocBuilderTemplate = new GrpcDocBuilderTemplate(); - grpcDocBuilderTemplate.checkAndInit(apiConfig, Boolean.TRUE); - List apiDocList = grpcDocBuilderTemplate.getRpcApiDoc(apiConfig, javaProjectBuilder); + List apiDocList = grpcDocBuilderTemplate.getApiDoc(false, true, false, apiConfig, + javaProjectBuilder); if (apiConfig.isAllInOne()) { String version = apiConfig.isCoverOld() ? "" : "-V" + DateTimeUtil.long2Str(System.currentTimeMillis(), DocGlobalConstants.DATE_FORMAT_YYYY_MM_DD_HH_MM); @@ -66,7 +65,7 @@ public static void buildApiDoc(ApiConfig apiConfig, JavaProjectBuilder javaProje DocGlobalConstants.GRPC_ALL_IN_ONE_MD_TPL, docName); } else { - grpcDocBuilderTemplate.buildApiDoc(apiDocList, apiConfig, DocGlobalConstants.RPC_API_DOC_MD_TPL, + grpcDocBuilderTemplate.buildApiDoc(apiDocList, apiConfig, DocGlobalConstants.GRPC_API_MD_TPL, DocGlobalConstants.MARKDOWN_API_FILE_EXTENSION); grpcDocBuilderTemplate.buildErrorCodeDoc(apiConfig, DocGlobalConstants.ERROR_CODE_LIST_MD_TPL, diff --git a/src/main/java/com/ly/doc/builder/javadoc/JavadocAdocBuilder.java b/src/main/java/com/ly/doc/builder/javadoc/JavadocAdocBuilder.java index 2d979b74..da4d64ef 100644 --- a/src/main/java/com/ly/doc/builder/javadoc/JavadocAdocBuilder.java +++ b/src/main/java/com/ly/doc/builder/javadoc/JavadocAdocBuilder.java @@ -49,12 +49,10 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { - config.setAdoc(true); JavadocDocBuilderTemplate builderTemplate = new JavadocDocBuilderTemplate(); - builderTemplate.checkAndInit(config, Boolean.TRUE); - List apiDocList = builderTemplate.getJavadocApiDoc(config, javaProjectBuilder); + List apiDocList = builderTemplate.getApiDoc(true, true, false, config, javaProjectBuilder); if (config.isAllInOne()) { - String docName = builderTemplate.allInOneDocName(config, INDEX_DOC, ".adoc"); + String docName = builderTemplate.allInOneDocName(config, INDEX_DOC, DocGlobalConstants.ASCIIDOC_EXTENSION); builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, DocGlobalConstants.JAVADOC_ALL_IN_ONE_ADOC_TPL, docName); } diff --git a/src/main/java/com/ly/doc/builder/javadoc/JavadocDocBuilderTemplate.java b/src/main/java/com/ly/doc/builder/javadoc/JavadocDocBuilderTemplate.java index 2268e74b..f3e5479a 100644 --- a/src/main/java/com/ly/doc/builder/javadoc/JavadocDocBuilderTemplate.java +++ b/src/main/java/com/ly/doc/builder/javadoc/JavadocDocBuilderTemplate.java @@ -51,7 +51,7 @@ * * @author chenchuxin */ -public class JavadocDocBuilderTemplate implements IBaseDocBuilderTemplate { +public class JavadocDocBuilderTemplate implements IBaseDocBuilderTemplate { private static final String DEPENDENCY_TITLE = "Add dependency"; @@ -98,7 +98,7 @@ public void buildAllInOne(List apiDocList, ApiConfig config, Java Template tpl = BeetlTemplateUtil.getByName(template); tpl.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList); // binding common variable - IBaseDocBuilderTemplate.super.bindingCommonVariable(config, javaProjectBuilder, tpl, apiDocList.isEmpty()); + this.bindingCommonVariable(config, javaProjectBuilder, tpl, apiDocList.isEmpty()); FileUtil.nioWriteFile(tpl.render(), outPath + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); } @@ -143,22 +143,6 @@ public void buildSearchJs(List apiDocList, ApiConfig config, Java FileUtil.nioWriteFile(tpl.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); } - /** - * build error_code adoc - * @param config api config - * @param template template - * @param outPutFileName output file - * @param javaProjectBuilder javaProjectBuilder - */ - public void buildErrorCodeDoc(ApiConfig config, String template, String outPutFileName, - JavaProjectBuilder javaProjectBuilder) { - List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); - Template mapper = BeetlTemplateUtil.getByName(template); - mapper.binding(TemplateVariable.LIST.getVariable(), errorCodeList); - FileUtil.nioWriteFile(mapper.render(), - config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); - } - /** * get all api data * @param config ApiConfig @@ -188,6 +172,12 @@ private List listOfApiData(ApiConfig config, JavaProjectBuilder j return apiSchema.getApiDatas(); } + /** + * get all java doc api data + * @param config ApiConfig + * @param javaProjectBuilder JavaProjectBuilder + * @return ApiAllData + */ public List getJavadocApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { config.setShowJavaType(true); ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); diff --git a/src/main/java/com/ly/doc/builder/javadoc/JavadocHtmlBuilder.java b/src/main/java/com/ly/doc/builder/javadoc/JavadocHtmlBuilder.java index e15de63a..3ce9b6e3 100644 --- a/src/main/java/com/ly/doc/builder/javadoc/JavadocHtmlBuilder.java +++ b/src/main/java/com/ly/doc/builder/javadoc/JavadocHtmlBuilder.java @@ -46,8 +46,7 @@ public static void buildApiDoc(ApiConfig config) { */ public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { JavadocDocBuilderTemplate builderTemplate = new JavadocDocBuilderTemplate(); - builderTemplate.checkAndInit(config, Boolean.TRUE); - List apiDocList = builderTemplate.getJavadocApiDoc(config, javaProjectBuilder); + List apiDocList = builderTemplate.getApiDoc(false, true, false, config, javaProjectBuilder); builderTemplate.copyJQueryAndCss(config); String INDEX_HTML = "javadoc-index.html"; builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, diff --git a/src/main/java/com/ly/doc/builder/javadoc/JavadocMarkdownBuilder.java b/src/main/java/com/ly/doc/builder/javadoc/JavadocMarkdownBuilder.java index 43ec8ceb..c9c1b7f2 100644 --- a/src/main/java/com/ly/doc/builder/javadoc/JavadocMarkdownBuilder.java +++ b/src/main/java/com/ly/doc/builder/javadoc/JavadocMarkdownBuilder.java @@ -45,10 +45,8 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig apiConfig, JavaProjectBuilder javaProjectBuilder) { - apiConfig.setAdoc(Boolean.FALSE); JavadocDocBuilderTemplate builderTemplate = new JavadocDocBuilderTemplate(); - builderTemplate.checkAndInit(apiConfig, Boolean.TRUE); - List apiDocList = builderTemplate.getJavadocApiDoc(apiConfig, javaProjectBuilder); + List apiDocList = builderTemplate.getApiDoc(false, true, false, apiConfig, javaProjectBuilder); if (apiConfig.isAllInOne()) { String version = apiConfig.isCoverOld() ? "" : "-V" + DateTimeUtil.long2Str(System.currentTimeMillis(), DocGlobalConstants.DATE_FORMAT_YYYY_MM_DD_HH_MM); diff --git a/src/main/java/com/ly/doc/builder/rpc/RpcAdocBuilder.java b/src/main/java/com/ly/doc/builder/rpc/RpcAdocBuilder.java index 3914d812..44aca37b 100644 --- a/src/main/java/com/ly/doc/builder/rpc/RpcAdocBuilder.java +++ b/src/main/java/com/ly/doc/builder/rpc/RpcAdocBuilder.java @@ -20,14 +20,14 @@ */ package com.ly.doc.builder.rpc; -import java.util.List; - import com.ly.doc.constants.DocGlobalConstants; +import com.ly.doc.helper.JavaProjectBuilderHelper; import com.ly.doc.model.ApiConfig; import com.ly.doc.model.rpc.RpcApiDoc; -import com.ly.doc.helper.JavaProjectBuilderHelper; import com.thoughtworks.qdox.JavaProjectBuilder; +import java.util.List; + /** * @author yu 2020/5/17. */ @@ -52,12 +52,10 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { - config.setAdoc(true); RpcDocBuilderTemplate builderTemplate = new RpcDocBuilderTemplate(); - builderTemplate.checkAndInit(config, Boolean.TRUE); - List apiDocList = builderTemplate.getRpcApiDoc(config, javaProjectBuilder); + List apiDocList = builderTemplate.getApiDoc(true, true, false, config, javaProjectBuilder); if (config.isAllInOne()) { - String docName = builderTemplate.allInOneDocName(config, INDEX_DOC, ".adoc"); + String docName = builderTemplate.allInOneDocName(config, INDEX_DOC, DocGlobalConstants.ASCIIDOC_EXTENSION); builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, DocGlobalConstants.RPC_ALL_IN_ONE_ADOC_TPL, docName); } diff --git a/src/main/java/com/ly/doc/builder/rpc/RpcApiDataBuilder.java b/src/main/java/com/ly/doc/builder/rpc/RpcApiDataBuilder.java index 0c467ee0..80911ca4 100644 --- a/src/main/java/com/ly/doc/builder/rpc/RpcApiDataBuilder.java +++ b/src/main/java/com/ly/doc/builder/rpc/RpcApiDataBuilder.java @@ -21,13 +21,16 @@ package com.ly.doc.builder.rpc; import com.ly.doc.constants.FrameworkEnum; +import com.ly.doc.helper.JavaProjectBuilderHelper; import com.ly.doc.model.ApiConfig; import com.ly.doc.model.rpc.RpcApiAllData; +import com.ly.doc.model.rpc.RpcApiDoc; import com.power.common.util.StringUtil; -import com.ly.doc.helper.JavaProjectBuilderHelper; import com.thoughtworks.qdox.JavaProjectBuilder; /** + * rpc api data builder. + * * @author yu 2020/5/24. */ public class RpcApiDataBuilder { @@ -37,7 +40,7 @@ public class RpcApiDataBuilder { * @param config ApiConfig * @return List of ApiDoc */ - public static RpcApiAllData getApiData(ApiConfig config) { + public static RpcApiAllData getApiData(ApiConfig config) { config.setShowJavaType(true); if (StringUtil.isEmpty(config.getFramework())) { config.setFramework(FrameworkEnum.DUBBO.getFramework()); diff --git a/src/main/java/com/ly/doc/builder/rpc/RpcDocBuilderTemplate.java b/src/main/java/com/ly/doc/builder/rpc/RpcDocBuilderTemplate.java index 1d39fd3a..e988ef73 100644 --- a/src/main/java/com/ly/doc/builder/rpc/RpcDocBuilderTemplate.java +++ b/src/main/java/com/ly/doc/builder/rpc/RpcDocBuilderTemplate.java @@ -25,6 +25,7 @@ import com.ly.doc.constants.DocGlobalConstants; import com.ly.doc.constants.FrameworkEnum; import com.ly.doc.model.ApiConfig; +import com.ly.doc.model.rpc.RpcApiDoc; import com.power.common.util.StringUtil; /** @@ -32,7 +33,7 @@ * * @author yu 2020/5/16. */ -public class RpcDocBuilderTemplate implements IRpcDocBuilderTemplate { +public class RpcDocBuilderTemplate implements IRpcDocBuilderTemplate { @Override public void checkAndInit(ApiConfig config, boolean checkOutPath) { @@ -43,4 +44,9 @@ public void checkAndInit(ApiConfig config, boolean checkOutPath) { config.setOutPath(config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + DocGlobalConstants.RPC_OUT_DIR); } + @Override + public RpcApiDoc createEmptyApiDoc() { + return new RpcApiDoc(); + } + } diff --git a/src/main/java/com/ly/doc/builder/rpc/RpcHtmlBuilder.java b/src/main/java/com/ly/doc/builder/rpc/RpcHtmlBuilder.java index 23773032..0abbf4e8 100644 --- a/src/main/java/com/ly/doc/builder/rpc/RpcHtmlBuilder.java +++ b/src/main/java/com/ly/doc/builder/rpc/RpcHtmlBuilder.java @@ -49,8 +49,7 @@ public static void buildApiDoc(ApiConfig config) { */ public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { RpcDocBuilderTemplate builderTemplate = new RpcDocBuilderTemplate(); - builderTemplate.checkAndInit(config, Boolean.TRUE); - List apiDocList = builderTemplate.getRpcApiDoc(config, javaProjectBuilder); + List apiDocList = builderTemplate.getApiDoc(false, true, false, config, javaProjectBuilder); builderTemplate.copyJQueryAndCss(config); String INDEX_HTML = "rpc-index.html"; builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, diff --git a/src/main/java/com/ly/doc/builder/rpc/RpcMarkdownBuilder.java b/src/main/java/com/ly/doc/builder/rpc/RpcMarkdownBuilder.java index b64fad45..27da9817 100644 --- a/src/main/java/com/ly/doc/builder/rpc/RpcMarkdownBuilder.java +++ b/src/main/java/com/ly/doc/builder/rpc/RpcMarkdownBuilder.java @@ -48,10 +48,8 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig apiConfig, JavaProjectBuilder javaProjectBuilder) { - apiConfig.setAdoc(Boolean.FALSE); RpcDocBuilderTemplate builderTemplate = new RpcDocBuilderTemplate(); - builderTemplate.checkAndInit(apiConfig, Boolean.TRUE); - List apiDocList = builderTemplate.getRpcApiDoc(apiConfig, javaProjectBuilder); + List apiDocList = builderTemplate.getApiDoc(false, true, false, apiConfig, javaProjectBuilder); if (apiConfig.isAllInOne()) { String version = apiConfig.isCoverOld() ? "" : "-V" + DateTimeUtil.long2Str(System.currentTimeMillis(), DocGlobalConstants.DATE_FORMAT_YYYY_MM_DD_HH_MM); diff --git a/src/main/java/com/ly/doc/builder/rpc/RpcTornaBuilder.java b/src/main/java/com/ly/doc/builder/rpc/RpcTornaBuilder.java index d0749572..d32805a0 100644 --- a/src/main/java/com/ly/doc/builder/rpc/RpcTornaBuilder.java +++ b/src/main/java/com/ly/doc/builder/rpc/RpcTornaBuilder.java @@ -20,22 +20,21 @@ */ package com.ly.doc.builder.rpc; -import java.util.ArrayList; -import java.util.List; - import com.ly.doc.constants.TornaConstants; +import com.ly.doc.helper.JavaProjectBuilderHelper; import com.ly.doc.model.ApiConfig; import com.ly.doc.model.rpc.RpcApiDoc; import com.ly.doc.model.torna.Apis; import com.ly.doc.model.torna.DubboInfo; -import com.ly.doc.utils.TornaUtil; -import com.ly.doc.helper.JavaProjectBuilderHelper; import com.ly.doc.model.torna.TornaApi; +import com.ly.doc.utils.TornaUtil; import com.thoughtworks.qdox.JavaProjectBuilder; - import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import java.util.ArrayList; +import java.util.List; + /** * @author xingzi 2021/4/28 16:14 **/ @@ -56,10 +55,8 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { - config.setParamsDataToTree(true); RpcDocBuilderTemplate builderTemplate = new RpcDocBuilderTemplate(); - builderTemplate.checkAndInit(config, Boolean.FALSE); - List apiDocList = builderTemplate.getRpcApiDoc(config, javaProjectBuilder); + List apiDocList = builderTemplate.getApiDoc(false, true, true, config, javaProjectBuilder); buildTorna(apiDocList, config, javaProjectBuilder); } diff --git a/src/main/java/com/ly/doc/builder/websocket/WebSocketAsciidocBuilder.java b/src/main/java/com/ly/doc/builder/websocket/WebSocketAsciidocBuilder.java new file mode 100644 index 00000000..7175021f --- /dev/null +++ b/src/main/java/com/ly/doc/builder/websocket/WebSocketAsciidocBuilder.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2018-2024 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.ly.doc.builder.websocket; + +import com.ly.doc.constants.DocGlobalConstants; +import com.ly.doc.helper.JavaProjectBuilderHelper; +import com.ly.doc.model.ApiConfig; +import com.ly.doc.model.WebSocketDoc; +import com.thoughtworks.qdox.JavaProjectBuilder; + +import java.util.List; + +/** + * use to create websocket ascii doc. + * + * @author linwumingshi + * @since 3.0.7 + */ +public class WebSocketAsciidocBuilder { + + /** + * websocket api extension. + */ + private static final String API_EXTENSION = "WebsocketApi.adoc"; + + /** + * websocket index extension. + */ + private static final String INDEX_DOC = "websocket-index.adoc"; + + /** + * build websocket ascii doc. + * @param config ApiConfig + */ + public static void buildApiDoc(ApiConfig config) { + JavaProjectBuilder javaProjectBuilder = JavaProjectBuilderHelper.create(); + buildApiDoc(config, javaProjectBuilder); + } + + /** + * Only for smart-doc maven plugin and gradle plugin. + * @param config ApiConfig + * @param javaProjectBuilder ProjectDocConfigBuilder + */ + public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { + + WebSocketDocBuilderTemplate webSocketDocBuilderTemplate = new WebSocketDocBuilderTemplate(); + List webSocketDocList = webSocketDocBuilderTemplate.getWebSocketApiDoc(Boolean.TRUE, config, + javaProjectBuilder); + + if (null == webSocketDocList || webSocketDocList.isEmpty()) { + return; + } + + if (config.isAllInOne()) { + String docName = webSocketDocBuilderTemplate.allInOneDocName(config, INDEX_DOC, + DocGlobalConstants.ASCIIDOC_EXTENSION); + webSocketDocBuilderTemplate.buildWebSocketAllInOne(webSocketDocList, config, javaProjectBuilder, + DocGlobalConstants.WEBSOCKET_ALL_IN_ONE_ADOC_TPL, docName); + } + else { + webSocketDocBuilderTemplate.buildWebSocketApiDoc(webSocketDocList, config, + DocGlobalConstants.WEBSOCKET_API_DOC_ADOC_TPL, API_EXTENSION); + webSocketDocBuilderTemplate.buildErrorCodeDoc(config, DocGlobalConstants.ERROR_CODE_LIST_ADOC_TPL, + DocGlobalConstants.ERROR_CODE_LIST_ADOC, javaProjectBuilder); + } + } + +} diff --git a/src/main/java/com/ly/doc/builder/websocket/WebSocketDocBuilderTemplate.java b/src/main/java/com/ly/doc/builder/websocket/WebSocketDocBuilderTemplate.java new file mode 100644 index 00000000..cf92cab5 --- /dev/null +++ b/src/main/java/com/ly/doc/builder/websocket/WebSocketDocBuilderTemplate.java @@ -0,0 +1,181 @@ +/* + * + * Copyright (C) 2018-2024 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.ly.doc.builder.websocket; + +import com.ly.doc.builder.IBaseDocBuilderTemplate; +import com.ly.doc.builder.ProjectDocConfigBuilder; +import com.ly.doc.constants.DocGlobalConstants; +import com.ly.doc.constants.HighlightStyle; +import com.ly.doc.constants.TemplateVariable; +import com.ly.doc.factory.BuildTemplateFactory; +import com.ly.doc.model.ApiConfig; +import com.ly.doc.model.ApiDocDict; +import com.ly.doc.model.ApiErrorCode; +import com.ly.doc.model.WebSocketDoc; +import com.ly.doc.template.IWebSocketDocBuildTemplate; +import com.ly.doc.utils.BeetlTemplateUtil; +import com.ly.doc.utils.DocUtil; +import com.power.common.util.CollectionUtil; +import com.power.common.util.FileUtil; +import com.thoughtworks.qdox.JavaProjectBuilder; +import org.beetl.core.Template; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * WebSocket doc builder template. + * + * @author linwumingshi + * @since 3.0.7 + */ +public class WebSocketDocBuilderTemplate implements IBaseDocBuilderTemplate { + + /** + * get all websocket api data. + * @param adoc is adoc + * @param config ApiConfig + * @param javaProjectBuilder JavaProjectBuilder + * @return ApiAllData + */ + public List getWebSocketApiDoc(boolean adoc, ApiConfig config, + JavaProjectBuilder javaProjectBuilder) { + config.setAdoc(adoc); + this.checkAndInit(config, Boolean.TRUE); + config.setParamsDataToTree(false); + config + .setOutPath(config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + DocGlobalConstants.WEBSOCKET_OUT_DIR); + return this.getWebSocketApiDoc(config, javaProjectBuilder); + + } + + /** + * get all websocket api data. + * @param config ApiConfig + * @param javaProjectBuilder JavaProjectBuilder + * @return ApiAllData + */ + public List getWebSocketApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { + config.setShowJavaType(false); + ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); + IWebSocketDocBuildTemplate webSocketDocBuildTemplate = BuildTemplateFactory + .getWebSocketDocBuildTemplate(config.getFramework(), config.getClassLoader()); + Objects.requireNonNull(webSocketDocBuildTemplate, "doc build websocket template is null"); + return webSocketDocBuildTemplate.getWebSocketData(configBuilder); + } + + /** + * Merge all websocket api doc into one document. + * @param webSocketDocList list data of Api doc + * @param config api config + * @param template template + * @param outPutFileName output file + */ + public void buildWebSocketAllInOne(List webSocketDocList, ApiConfig config, + JavaProjectBuilder javaProjectBuilder, String template, String outPutFileName) { + String outPath = config.getOutPath(); + FileUtil.mkdirs(outPath); + Template tpl = BeetlTemplateUtil.getByName(template); + String style = config.getStyle(); + tpl.binding(TemplateVariable.STYLE.getVariable(), style); + tpl.binding(TemplateVariable.HIGH_LIGHT_CSS_LINK.getVariable(), config.getHighlightStyleLink()); + tpl.binding(TemplateVariable.BACKGROUND.getVariable(), HighlightStyle.getBackgroundColor(style)); + tpl.binding(TemplateVariable.WEBSOCKET_DOC_LIST.getVariable(), webSocketDocList); + tpl.binding(TemplateVariable.LANGUAGE.getVariable(), config.getLanguage()); + this.setCssCDN(config, tpl); + // binding common variable + this.bindingCommonVariable(config, javaProjectBuilder, tpl, webSocketDocList.isEmpty()); + FileUtil.nioWriteFile(tpl.render(), outPath + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); + } + + /** + * Generate websocket api documentation for all controllers. + * @param apiDocList list of api doc + * @param config api config + * @param template template + * @param fileExtension file extension + */ + public void buildWebSocketApiDoc(List apiDocList, ApiConfig config, String template, + String fileExtension) { + FileUtil.mkdirs(config.getOutPath()); + for (WebSocketDoc doc : apiDocList) { + Template mapper = this.buildWebSocketApiDocTemplate(doc, config, template); + FileUtil.nioWriteFile(mapper.render(), + config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + doc.getName() + fileExtension); + } + } + + /** + * build websocket api doc template + * @param webSocketDoc websocket api doc + * @param config api config + * @param template template + * @return Template + */ + public Template buildWebSocketApiDocTemplate(WebSocketDoc webSocketDoc, ApiConfig config, String template) { + Template mapper = BeetlTemplateUtil.getByName(template); + mapper.binding(TemplateVariable.DEPRECATED.getVariable(), webSocketDoc.getDeprecated()); + mapper.binding(TemplateVariable.DESC.getVariable(), webSocketDoc.getDesc()); + mapper.binding(TemplateVariable.URI.getVariable(), webSocketDoc.getUri()); + mapper.binding(TemplateVariable.AUTHOR.getVariable(), webSocketDoc.getAuthor()); + mapper.binding(TemplateVariable.SUB_PROTOCOLS.getVariable(), webSocketDoc.getSubProtocols()); + mapper.binding(TemplateVariable.WEBSOCKET_PATH_PARAMS.getVariable(), webSocketDoc.getPathParams()); + return mapper; + } + + /** + * Build search js. + * @param apiDocList list data of Api doc + * @param config api config + * @param javaProjectBuilder projectBuilder + * @param template template + * @param outPutFileName output file + */ + public void buildSearchJs(List apiDocList, ApiConfig config, JavaProjectBuilder javaProjectBuilder, + String template, String outPutFileName) { + List errorCodeList = DocUtil.errorCodeDictToList(config, javaProjectBuilder); + Template tpl = BeetlTemplateUtil.getByName(template); + // add order + List apiDocs = new ArrayList<>(); + for (WebSocketDoc apiDoc1 : apiDocList) { + apiDoc1.setOrder(apiDocs.size() + 1); + apiDocs.add(apiDoc1); + } + Map titleMap = this.setDirectoryLanguageVariable(config, tpl); + if (CollectionUtil.isNotEmpty(errorCodeList)) { + WebSocketDoc apiDoc1 = new WebSocketDoc(); + apiDoc1.setOrder(apiDocs.size() + 1); + apiDoc1.setDesc(titleMap.get(TemplateVariable.ERROR_LIST_TITLE.getVariable())); + apiDoc1.setList(new ArrayList<>(0)); + apiDocs.add(apiDoc1); + } + + // set dict list + List apiDocDictList = DocUtil.buildDictionary(config, javaProjectBuilder); + tpl.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList); + tpl.binding(TemplateVariable.DIRECTORY_TREE.getVariable(), apiDocs); + FileUtil.nioWriteFile(tpl.render(), config.getOutPath() + DocGlobalConstants.FILE_SEPARATOR + outPutFileName); + } + +} diff --git a/src/main/java/com/ly/doc/builder/websocket/WebSocketHtmlBuilder.java b/src/main/java/com/ly/doc/builder/websocket/WebSocketHtmlBuilder.java new file mode 100644 index 00000000..dbb9c4fd --- /dev/null +++ b/src/main/java/com/ly/doc/builder/websocket/WebSocketHtmlBuilder.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2018-2024 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.ly.doc.builder.websocket; + +import com.ly.doc.constants.DocGlobalConstants; +import com.ly.doc.helper.JavaProjectBuilderHelper; +import com.ly.doc.model.ApiConfig; +import com.ly.doc.model.WebSocketDoc; +import com.thoughtworks.qdox.JavaProjectBuilder; + +import java.util.List; + +/** + * use to create websocket Html doc. + * + * @author linwumingshi + * @since 3.0.7 + */ +public class WebSocketHtmlBuilder { + + /** + * index.html + */ + private final static String INDEX_HTML = "websocket-index.html"; + + /** + * build websocket html doc. + * @param config ApiConfig + */ + public static void buildApiDoc(ApiConfig config) { + JavaProjectBuilder javaProjectBuilder = JavaProjectBuilderHelper.create(); + buildApiDoc(config, javaProjectBuilder); + } + + /** + * Only for smart-doc maven plugin and gradle plugin. + * @param config ApiConfig + * @param javaProjectBuilder ProjectDocConfigBuilder + */ + public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { + WebSocketDocBuilderTemplate webSocketDocBuilderTemplate = new WebSocketDocBuilderTemplate(); + List webSocketDocList = webSocketDocBuilderTemplate.getWebSocketApiDoc(Boolean.FALSE, config, + javaProjectBuilder); + + if (null == webSocketDocList || webSocketDocList.isEmpty()) { + return; + } + webSocketDocBuilderTemplate.copyJQueryAndCss(config); + webSocketDocBuilderTemplate.buildWebSocketAllInOne(webSocketDocList, config, javaProjectBuilder, + DocGlobalConstants.WEBSOCKET_ALL_IN_ONE_HTML_TPL, INDEX_HTML); + webSocketDocBuilderTemplate.buildSearchJs(webSocketDocList, config, javaProjectBuilder, + DocGlobalConstants.WEBSOCKET_ALL_IN_ONE_SEARCH_TPL, DocGlobalConstants.SEARCH_JS_OUT); + + } + +} diff --git a/src/main/java/com/ly/doc/builder/websocket/WebSocketMarkdownBuilder.java b/src/main/java/com/ly/doc/builder/websocket/WebSocketMarkdownBuilder.java index 7c89a42d..d60e11f6 100644 --- a/src/main/java/com/ly/doc/builder/websocket/WebSocketMarkdownBuilder.java +++ b/src/main/java/com/ly/doc/builder/websocket/WebSocketMarkdownBuilder.java @@ -20,27 +20,25 @@ */ package com.ly.doc.builder.websocket; -import com.ly.doc.builder.DocBuilderTemplate; -import com.ly.doc.builder.ProjectDocConfigBuilder; import com.ly.doc.constants.DocGlobalConstants; -import com.ly.doc.factory.BuildTemplateFactory; import com.ly.doc.helper.JavaProjectBuilderHelper; import com.ly.doc.model.ApiConfig; import com.ly.doc.model.WebSocketDoc; -import com.ly.doc.template.IWebSocketDocBuildTemplate; import com.power.common.util.DateTimeUtil; import com.thoughtworks.qdox.JavaProjectBuilder; import java.util.List; /** - * use to create websocket Markdown doc + * use to create websocket Markdown doc. * * @author linwumingshi + * @since 3.0.3 */ public class WebSocketMarkdownBuilder { /** + * build websocket Markdown doc. * @param config ApiConfig */ public static void buildApiDoc(ApiConfig config) { @@ -54,24 +52,29 @@ public static void buildApiDoc(ApiConfig config) { * @param javaProjectBuilder ProjectDocConfigBuilder */ public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { - DocBuilderTemplate builderTemplate = new DocBuilderTemplate(); - builderTemplate.checkAndInit(config, Boolean.TRUE); - config.setAdoc(false); - config.setParamsDataToTree(false); - ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); - IWebSocketDocBuildTemplate docBuildTemplate = BuildTemplateFactory - .getWebSocketDocBuildTemplate(config.getFramework(), config.getClassLoader()); - List webSocketDocList = docBuildTemplate.getWebSocketData(configBuilder); + WebSocketDocBuilderTemplate webSocketDocBuilderTemplate = new WebSocketDocBuilderTemplate(); + List webSocketDocList = webSocketDocBuilderTemplate.getWebSocketApiDoc(Boolean.FALSE, config, + javaProjectBuilder); + if (null == webSocketDocList || webSocketDocList.isEmpty()) { return; } - String version = config.isCoverOld() ? "" : "-V" - + DateTimeUtil.long2Str(System.currentTimeMillis(), DocGlobalConstants.DATE_FORMAT_YYYY_MM_DD_HH_MM); - String docName = builderTemplate.allInOneDocName(config, - "WebSocket" + version + DocGlobalConstants.MARKDOWN_EXTENSION, DocGlobalConstants.MARKDOWN_EXTENSION); - builderTemplate.buildWebSocket(webSocketDocList, config, javaProjectBuilder, - DocGlobalConstants.WEBSOCKET_ALL_IN_ONE_MD_TPL, docName); + if (config.isAllInOne()) { + String version = config.isCoverOld() ? "" : "-V" + DateTimeUtil.long2Str(System.currentTimeMillis(), + DocGlobalConstants.DATE_FORMAT_YYYY_MM_DD_HH_MM); + String docName = webSocketDocBuilderTemplate.allInOneDocName(config, "webSocket-all" + version, + DocGlobalConstants.MARKDOWN_EXTENSION); + webSocketDocBuilderTemplate.buildWebSocketAllInOne(webSocketDocList, config, javaProjectBuilder, + DocGlobalConstants.WEBSOCKET_ALL_IN_ONE_MD_TPL, docName); + } + else { + webSocketDocBuilderTemplate.buildWebSocketApiDoc(webSocketDocList, config, + DocGlobalConstants.WEBSOCKET_MD_TPL, DocGlobalConstants.MARKDOWN_API_FILE_EXTENSION); + + webSocketDocBuilderTemplate.buildErrorCodeDoc(config, DocGlobalConstants.ERROR_CODE_LIST_MD_TPL, + DocGlobalConstants.ERROR_CODE_LIST_MD, javaProjectBuilder); + } } } diff --git a/src/main/java/com/ly/doc/constants/DocGlobalConstants.java b/src/main/java/com/ly/doc/constants/DocGlobalConstants.java index f67bef23..343dfdf0 100644 --- a/src/main/java/com/ly/doc/constants/DocGlobalConstants.java +++ b/src/main/java/com/ly/doc/constants/DocGlobalConstants.java @@ -20,21 +20,40 @@ */ package com.ly.doc.constants; +import java.nio.file.FileSystems; + /** + * doc global constants. + * * @author yu 2018/12/15. */ public interface DocGlobalConstants { int API_ORDER = 0; - String FILE_SEPARATOR = System.getProperty("file.separator"); + /** + * File separator. + */ + String FILE_SEPARATOR = FileSystems.getDefault().getSeparator(); + /** + * html api doc out path. + */ String HTML_DOC_OUT_PATH = "src/main/resources/static/doc"; + /** + * asciidoc api doc out path. + */ String ADOC_OUT_PATH = "src/docs/asciidoc"; + /** + * project code path. + */ String PROJECT_CODE_PATH = "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "java"; + /** + * Absolute path of project code. + */ String ABSOLUTE_CODE_PATH = System.getProperty("user.dir") + FILE_SEPARATOR + PROJECT_CODE_PATH; /** @@ -42,10 +61,19 @@ public interface DocGlobalConstants { */ String ABSOLUTE_TARGET_CLASS_PATH = System.getProperty("user.dir") + "/target/classes"; + /** + * Language. + */ String DOC_LANGUAGE = "smart-doc_language"; + /** + * random mock. + */ String RANDOM_MOCK = "randomMock"; + /** + * api doc template. + */ String API_DOC_MD_TPL = "ApiDoc.md"; /** @@ -53,214 +81,513 @@ public interface DocGlobalConstants { */ String MARKDOWN_API_FILE_EXTENSION = "Api.md"; + /** + * jmeter template. + */ String JMETER_TPL = "JMeter.jmx"; + /** + * api doc asciidoc template. + */ String API_DOC_ADOC_TPL = "ApiDoc.adoc"; + /** + * all in one api doc markdown template. + */ String ALL_IN_ONE_MD_TPL = "AllInOne.md"; + /** + * all in one api doc ascii template. + */ String ALL_IN_ONE_ADOC_TPL = "AllInOne.adoc"; + /** + * all in one api doc html template. + */ String ALL_IN_ONE_HTML_TPL = "AllInOne.html"; + /** + * all in one api doc word template. + */ String ALL_IN_ONE_WORD_XML_TPL = "word/AllInOneWordTemplate.xml"; + /** + * word template xml file. + */ String WORD_XML_TPL = "word/index.xml"; + /** + * word error template xml file. + */ String WORD_ERROR_XML_TPL = "word/error.xml"; + /** + * word dictionary template xml file. + */ String WORD_DICT_XML_TPL = "word/dict.xml"; + /** + * html api doc template. + */ String HTML_API_DOC_TPL = "HtmlApiDoc.html"; + /** + * error code list api doc template. + */ String ERROR_CODE_LIST_MD_TPL = "ErrorCodeList.md"; + /** + * error code list api doc ascii template. + */ String ERROR_CODE_LIST_ADOC_TPL = "ErrorCodeList.adoc"; + /** + * error code list api doc markdown template. + */ String ERROR_CODE_LIST_MD = "ErrorCodeList.md"; + /** + * error code list api doc ascii template. + */ String ERROR_CODE_LIST_ADOC = "ErrorCodeList.adoc"; + /** + * dictionary api doc template. + */ String DICT_LIST_MD = "Dictionary.md"; + /** + * dictionary api doc template. + */ String DICT_LIST_MD_TPL = "Dictionary.md"; + /** + * dictionary api doc ascii template. + */ String DICT_LIST_ADOC = "Dictionary.adoc"; + /** + * dictionary api doc template. + */ String DICT_LIST_ADOC_TPL = "Dictionary.md"; + /** + * search js template. + */ String SEARCH_ALL_JS_TPL = "js/search_all.js.btl"; + /** + * search js template. + */ String SEARCH_JS_TPL = "js/search.js.btl"; + /** + * search js. + */ String SEARCH_JS_OUT = "search.js"; + /** + * debug js template. + */ String DEBUG_JS_TPL = "js/debug.js"; + /** + * debug js. + */ String DEBUG_JS_OUT = "debug.js"; + /** + * debug page template. + */ String DEBUG_PAGE_TPL = "mock.html"; + /** + * debug page template. + */ String DEBUG_PAGE_ALL_TPL = "debug-all.html"; + /** + * debug page template. + */ String DEBUG_PAGE_SINGLE_TPL = "html/debug.html"; + /** + * index page template. + */ String SINGLE_INDEX_HTML_TPL = "html/index.html"; + /** + * error page template. + */ String SINGLE_ERROR_HTML_TPL = "html/error.html"; + /** + * dict page template. + */ String SINGLE_DICT_HTML_TPL = "html/dict.html"; + /** + * index page template. + */ String ALL_IN_ONE_CSS = "css/AllInOne.css"; + /** + * index page. + */ String ALL_IN_ONE_CSS_OUT = "AllInOne.css"; + /** + * font style. + */ String FONT_STYLE = "font.css"; + /** + * highlight js. + */ String HIGH_LIGHT_JS = "highlight.min.js"; + /** + * jquery. + */ String JQUERY = "jquery.min.js"; + /** + * highlight style. + */ String HIGH_LIGHT_STYLE = "xt256.min.css"; + /** + * rpc out dir. + */ String RPC_OUT_DIR = "rpc"; + /** + * javadoc out dir. + */ String JAVADOC_OUT_DIR = "javadoc"; + /** + * javadoc all in one html template. + */ String JAVADOC_ALL_IN_ONE_HTML_TPL = "javadoc/JavadocAllInOne.html"; + /** + * javadoc all in one search template. + */ String JAVADOC_ALL_IN_ONE_SEARCH_TPL = "javadoc/JavadocSearch.btl"; + /** + * javadoc all in one markdown template. + */ String JAVADOC_ALL_IN_ONE_MD_TPL = "javadoc/JavadocAllInOne.md"; + /** + * javadoc api doc template. + */ String JAVADOC_API_DOC_MD_TPL = "javadoc/Javadoc.md"; + /** + * javadoc all in one ascii template. + */ String JAVADOC_ALL_IN_ONE_ADOC_TPL = "javadoc/JavadocAllInOne.adoc"; + /** + * javadoc api doc ascii template. + */ String JAVADOC_API_DOC_ADOC_TPL = "javadoc/Javadoc.adoc"; + /** + * rpc api doc asciidoc template. + */ String RPC_API_DOC_ADOC_TPL = "dubbo/Dubbo.adoc"; + /** + * rpc all in one ascii template. + */ String RPC_ALL_IN_ONE_ADOC_TPL = "dubbo/DubboAllInOne.adoc"; + /** + * rpc all in one html template. + */ String RPC_ALL_IN_ONE_HTML_TPL = "dubbo/DubboAllInOne.html"; + /** + * rpc all in one search template. + */ String RPC_ALL_IN_ONE_SEARCH_TPL = "dubbo/DubboSearch.btl"; + /** + * rpc api dependency template. + */ String RPC_DEPENDENCY_MD_TPL = "dubbo/DubboApiDependency.md"; + /** + * rpc api dependency template. + */ String RPC_DEPENDENCY_EMPTY_MD_TPL = "dubbo/DubboApiDependencyEmpty.md"; + /** + * rpc api doc markdown template. + */ String RPC_API_DOC_MD_TPL = "dubbo/Dubbo.md"; + /** + * rpc all in one markdown template. + */ String RPC_ALL_IN_ONE_MD_TPL = "dubbo/DubboAllInOne.md"; + /** + * rpc index template. + */ String RPC_INDEX_TPL = "dubbo/DubboIndex.btl"; + /** + * postman json. + */ String POSTMAN_JSON = "/postman.json"; + /** + * open api json. + */ String OPEN_API_JSON = "/openapi.json"; + /** + * spring ModelAndView. + */ String MODE_AND_VIEW_FULLY = "org.springframework.web.servlet.ModelAndView"; + /** + * feign client. + */ String FEIGN_CLIENT_FULLY = "org.springframework.cloud.netflix.feign.FeignClient"; + /** + * feign client. + */ String FEIGN_CLIENT = "FeignClient"; + /** + * default version. + */ String DEFAULT_VERSION = "-"; + /** + * error code list chinese title. + */ String ERROR_CODE_LIST_CN_TITLE = "错误码列表"; + /** + * error code list english title. + */ String ERROR_CODE_LIST_EN_TITLE = "Error Code List"; + /** + * dictionary chinese title. + */ String DICT_CN_TITLE = "数据字典"; + /** + * dictionary english title. + */ String DICT_EN_TITLE = "Data Dictionaries"; + /** + * field space. + */ String FIELD_SPACE = "     "; + /** + * any object msg. + */ String ANY_OBJECT_MSG = "any object."; + /** + * no comments found. + */ String NO_COMMENTS_FOUND = "No comments found."; + /** + * spring web annotation package. + */ String SPRING_WEB_ANNOTATION_PACKAGE = "org.springframework.web.bind.annotation"; + /** + * postman mode formdata. + */ String POSTMAN_MODE_FORMDATA = "formdata"; + /** + * postman mode raw. + */ String POSTMAN_MODE_RAW = "raw"; + /** + * short multipart file. + */ String SHORT_MULTIPART_FILE_FULLY = "MultipartFile"; - String DEFAULT_SERVER_URL = ""; + /** + * empty. + */ + String EMPTY = ""; + + /** + * default server url. + */ + String DEFAULT_SERVER_URL = EMPTY; + /** + * short request body. + */ String SHORT_REQUEST_BODY = "RequestBody"; + /** + * curl request type. + */ String CURL_REQUEST_TYPE = "curl -X %s %s -i %s"; + /** + * curl request type data. + */ String CURL_REQUEST_TYPE_DATA = "curl -X %s %s -i %s --data '%s'"; + /** + * curl post put json. + */ String CURL_POST_PUT_JSON = "curl -X %s -H 'Content-Type: application/json;charset=UTF-8' %s -i %s --data '%s'"; - String EMPTY = ""; - + /** + * css cdn ch. + */ String CSS_CDN_CH = "https://fonts.googleapis.cnpmjs.org"; + /** + * css cdn. + */ String CSS_CDN = "https://fonts.googleapis.com"; + /** + * path delimiter. + */ String PATH_DELIMITER = "/"; + /** + * multi url separator. + */ String MULTI_URL_SEPARATOR = ";\t"; + /** + * param prefix. + */ String PARAM_PREFIX = "└─"; + /** + * openapi 2.0.0 component key. + */ String OPENAPI_2_COMPONENT_KRY = "#/definitions/"; + /** + * openapi 3.0.0 component key. + */ String OPENAPI_3_COMPONENT_KRY = "#/components/schemas/"; + /** + * default swagger tag. + */ String SWAGGER_FILE_TAG = "formData"; + /** + * default openapi tag. + */ String OPENAPI_TAG = "default"; + /** + * default filter method. + */ String DEFAULT_FILTER_METHOD = "*"; + /** + * jar temp path. + */ String JAR_TEMP = "./smart-temp/"; + /** + * default primitive. + */ String DEFAULT_PRIMITIVE = "defaultPrimitive"; + /** + * date format. + */ String DATE_FORMAT_YYYY_MM_DD_HH_MM = "yyyyMMddHHmm"; /** - * markdown extension + * markdown extension. */ String MARKDOWN_EXTENSION = ".md"; /** - * websocket all in one md tpl + * websocket all in one markdown template. + */ + String WEBSOCKET_ALL_IN_ONE_MD_TPL = "websocket/WebSocketAllOne.md"; + + /** + * websocket markdown template. + */ + String WEBSOCKET_MD_TPL = "websocket/WebSocket.md"; + + /** + * websocket all in one html template. */ - String WEBSOCKET_ALL_IN_ONE_MD_TPL = "WebSocket.md"; + String WEBSOCKET_ALL_IN_ONE_HTML_TPL = "websocket/WebSocketAllInOne.html"; /** - * grpc all in one md tpl. + * websocket all in one search template. + */ + String WEBSOCKET_ALL_IN_ONE_SEARCH_TPL = "websocket/WebSocketSearch.btl"; + + /** + * websocket api doc Asciidoc template. + */ + String WEBSOCKET_API_DOC_ADOC_TPL = "websocket/WebSocket.adoc"; + + /** + * websocket all in one Asciidoc template. + */ + String WEBSOCKET_ALL_IN_ONE_ADOC_TPL = "websocket/WebSocketAllInOne.adoc"; + + /** + * websocket api out dir. + */ + String WEBSOCKET_OUT_DIR = "websocket"; + + /** + * grpc all in one md template. */ String GRPC_ALL_IN_ONE_MD_TPL = "grpc/GrpcAllInOne.md"; /** - * grpc all in one html tpl. + * grpc md template. + */ + String GRPC_API_MD_TPL = "grpc/Grpc.md"; + + /** + * grpc all in one html template. */ String GRPC_ALL_IN_ONE_HTML_TPL = "grpc/GrpcAllInOne.html"; /** - * grpc all in one search tpl. + * grpc all in one search template. */ String GRPC_ALL_IN_ONE_SEARCH_TPL = "grpc/GrpcSearch.btl"; /** - * grpc api doc Asciidoc tpl. + * grpc api doc Asciidoc template. */ String GRPC_API_DOC_ADOC_TPL = "grpc/Grpc.adoc"; /** - * grpc all in one Asciidoc tpl. + * grpc all in one Asciidoc template. */ String GRPC_ALL_IN_ONE_ADOC_TPL = "grpc/GrpcAllInOne.adoc"; @@ -274,4 +601,9 @@ public interface DocGlobalConstants { */ String PROTO_FILE_SUFFIX = ".proto"; + /** + * asciidoc extension. + */ + String ASCIIDOC_EXTENSION = ".adoc"; + } diff --git a/src/main/java/com/ly/doc/constants/TemplateVariable.java b/src/main/java/com/ly/doc/constants/TemplateVariable.java index b2c02963..812a2644 100644 --- a/src/main/java/com/ly/doc/constants/TemplateVariable.java +++ b/src/main/java/com/ly/doc/constants/TemplateVariable.java @@ -177,7 +177,22 @@ public enum TemplateVariable { /** * jmeterPrometheusListener */ - JMETER_PROMETHEUS_LISTENER("jmeterPrometheusListener"),; + JMETER_PROMETHEUS_LISTENER("jmeterPrometheusListener"), + + /** + * subProtocols + */ + SUB_PROTOCOLS("subProtocols"), + + /** + * deprecated + */ + DEPRECATED("deprecated"), + + /** + * webSocketPathParams + */ + WEBSOCKET_PATH_PARAMS("pathParams"),; /** * variable diff --git a/src/main/java/com/ly/doc/model/AbstractRpcApiDoc.java b/src/main/java/com/ly/doc/model/AbstractRpcApiDoc.java new file mode 100644 index 00000000..6dc54a7e --- /dev/null +++ b/src/main/java/com/ly/doc/model/AbstractRpcApiDoc.java @@ -0,0 +1,189 @@ +package com.ly.doc.model; + +import com.power.common.util.CollectionUtil; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +/** + * Abstract API Doc. + * + * @param the type of method doc + */ +public abstract class AbstractRpcApiDoc + implements Serializable, IDoc, Comparable> { + + private static final long serialVersionUID = -3116322721344529338L; + + /** + * Order of controller + * + * @since 1.7+ + */ + protected int order; + + /** + * interface title + */ + protected String title; + + /** + * interface name + */ + protected String name; + + /** + * interface short name + */ + protected String shortName; + + /** + * controller alias handled by md5 + * + * @since 1.7+ + */ + protected String alias; + + /** + * method description + */ + protected String desc; + + /** + * interface protocol + */ + protected String protocol; + + /** + * interface author + */ + protected String author; + + /** + * interface uri + */ + protected String uri; + + /** + * interface version + */ + protected String version; + + /** + * List of method doc + */ + protected List list; + + public int getOrder() { + return order; + } + + public void setOrder(int order) { + this.order = order; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public String getShortName() { + return shortName; + } + + public void setShortName(String shortName) { + this.shortName = shortName; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + @Override + public int compareTo(AbstractRpcApiDoc o) { + if (Objects.nonNull(o.getDesc())) { + return desc.compareTo(o.getDesc()); + } + return name.compareTo(o.getName()); + } + + @Override + public String getDocClass() { + return this.name; + } + + @Override + public List getMethods() { + if (CollectionUtil.isEmpty(this.list)) { + return Collections.emptyList(); + } + return new ArrayList<>(this.list); + } + +} diff --git a/src/main/java/com/ly/doc/model/WebSocketDoc.java b/src/main/java/com/ly/doc/model/WebSocketDoc.java index b7b680b8..aa3d3af3 100644 --- a/src/main/java/com/ly/doc/model/WebSocketDoc.java +++ b/src/main/java/com/ly/doc/model/WebSocketDoc.java @@ -44,7 +44,7 @@ public class WebSocketDoc extends ApiDoc { /** * webSocket url */ - private String url; + private String uri; /** * webSocket deprecated @@ -71,12 +71,12 @@ public void setPathParams(List pathParams) { this.pathParams = pathParams; } - public String getUrl() { - return url; + public String getUri() { + return uri; } - public void setUrl(String url) { - this.url = url; + public void setUri(String uri) { + this.uri = uri; } public Boolean getDeprecated() { diff --git a/src/main/java/com/ly/doc/model/grpc/GrpcApiDoc.java b/src/main/java/com/ly/doc/model/grpc/GrpcApiDoc.java index 3460da70..29350836 100644 --- a/src/main/java/com/ly/doc/model/grpc/GrpcApiDoc.java +++ b/src/main/java/com/ly/doc/model/grpc/GrpcApiDoc.java @@ -20,15 +20,7 @@ */ package com.ly.doc.model.grpc; -import com.ly.doc.model.IDoc; -import com.ly.doc.model.IMethod; -import com.power.common.util.CollectionUtil; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import com.ly.doc.model.AbstractRpcApiDoc; /** * Grpc Api Doc. @@ -36,176 +28,6 @@ * @author linwumignshi * @since 3.0.7 */ -public class GrpcApiDoc implements Serializable, IDoc, Comparable { - - private static final long serialVersionUID = -3116322721344529338L; - - /** - * Order of controller - * - * @since 1.7+ - */ - public int order; - - /** - * interface title - */ - public String title; - - /** - * interface name - */ - private String name; - - /** - * interface short name - */ - private String shortName; - - /** - * controller alias handled by md5 - * - * @since 1.7+ - */ - private String alias; - - /** - * method description - */ - private String desc; - - /** - * interface protocol - */ - private String protocol; - - /** - * interface author - */ - private String author; - - /** - * interface uri - */ - private String uri; - - /** - * interface version - */ - private String version; - - /** - * List of method doc - */ - private List list; - - public int getOrder() { - return order; - } - - public void setOrder(int order) { - this.order = order; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAlias() { - return alias; - } - - public void setAlias(String alias) { - this.alias = alias; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public String getProtocol() { - return protocol; - } - - public void setProtocol(String protocol) { - this.protocol = protocol; - } - - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } - - public String getShortName() { - return shortName; - } - - public void setShortName(String shortName) { - this.shortName = shortName; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - @Override - public int compareTo(GrpcApiDoc o) { - if (Objects.nonNull(o.getDesc())) { - return desc.compareTo(o.getDesc()); - } - return name.compareTo(o.getName()); - } - - @Override - public String getDocClass() { - return this.name; - } - - @Override - public List getMethods() { - if (CollectionUtil.isEmpty(this.list)) { - return Collections.emptyList(); - } - return new ArrayList<>(this.list); - } +public class GrpcApiDoc extends AbstractRpcApiDoc { } diff --git a/src/main/java/com/ly/doc/model/rpc/RpcApiAllData.java b/src/main/java/com/ly/doc/model/rpc/RpcApiAllData.java index f868375a..d43468e8 100644 --- a/src/main/java/com/ly/doc/model/rpc/RpcApiAllData.java +++ b/src/main/java/com/ly/doc/model/rpc/RpcApiAllData.java @@ -20,16 +20,17 @@ */ package com.ly.doc.model.rpc; -import java.util.List; - -import com.ly.doc.model.ApiErrorCode; +import com.ly.doc.model.AbstractRpcApiDoc; import com.ly.doc.model.ApiDocDict; +import com.ly.doc.model.ApiErrorCode; import com.ly.doc.model.RevisionLog; +import java.util.List; + /** * @author yu 2020/5/24. */ -public class RpcApiAllData { +public class RpcApiAllData> { /** * project name @@ -49,7 +50,7 @@ public class RpcApiAllData { /** * doc list */ - private List apiDocList; + private List apiDocList; /** * @@ -95,11 +96,11 @@ public void setLanguage(String language) { this.language = language; } - public List getApiDocList() { + public List getApiDocList() { return apiDocList; } - public void setApiDocList(List apiDocList) { + public void setApiDocList(List apiDocList) { this.apiDocList = apiDocList; } diff --git a/src/main/java/com/ly/doc/model/rpc/RpcApiDoc.java b/src/main/java/com/ly/doc/model/rpc/RpcApiDoc.java index f0a26e10..71695537 100644 --- a/src/main/java/com/ly/doc/model/rpc/RpcApiDoc.java +++ b/src/main/java/com/ly/doc/model/rpc/RpcApiDoc.java @@ -20,173 +20,21 @@ */ package com.ly.doc.model.rpc; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import com.ly.doc.model.IDoc; -import com.ly.doc.model.IMethod; +import com.ly.doc.model.AbstractRpcApiDoc; import com.ly.doc.model.RpcJavaMethod; -import com.power.common.util.CollectionUtil; /** * @author yu 2020/5/16. */ -public class RpcApiDoc implements IDoc, Comparable { - - /** - * Order of controller - * - * @since 1.7+ - */ - public int order; - - /** - * interface title - */ - public String title; - - /** - * interface name - */ - private String name; - - /** - * interface short name - */ - private String shortName; - - /** - * controller alias handled by md5 - * - * @since 1.7+ - */ - private String alias; - - /** - * method description - */ - private String desc; - - /** - * interface protocol - */ - private String protocol; - - /** - * interface author - */ - private String author; +public class RpcApiDoc extends AbstractRpcApiDoc { - /** - * interface uri - */ - private String uri; - - /** - * interface version - */ - private String version; + private static final long serialVersionUID = -3116322721344529338L; /** * link */ private String link; - /** - * List of method doc - */ - private List list; - - public int getOrder() { - return order; - } - - public void setOrder(int order) { - this.order = order; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAlias() { - return alias; - } - - public void setAlias(String alias) { - this.alias = alias; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public String getProtocol() { - return protocol; - } - - public void setProtocol(String protocol) { - this.protocol = protocol; - } - - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } - - public String getShortName() { - return shortName; - } - - public void setShortName(String shortName) { - this.shortName = shortName; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - public String getLink() { return desc.replace(" ", "_").toLowerCase(); } @@ -195,25 +43,4 @@ public void setLink(String link) { this.link = link; } - @Override - public int compareTo(RpcApiDoc o) { - if (Objects.nonNull(o.getDesc())) { - return desc.compareTo(o.getDesc()); - } - return name.compareTo(o.getName()); - } - - @Override - public String getDocClass() { - return this.name; - } - - @Override - public List getMethods() { - if (CollectionUtil.isEmpty(this.list)) { - return Collections.emptyList(); - } - return new ArrayList<>(this.list); - } - } diff --git a/src/main/java/com/ly/doc/template/GRpcDocBuildTemplate.java b/src/main/java/com/ly/doc/template/GRpcDocBuildTemplate.java index 6a4bc900..16260a0f 100644 --- a/src/main/java/com/ly/doc/template/GRpcDocBuildTemplate.java +++ b/src/main/java/com/ly/doc/template/GRpcDocBuildTemplate.java @@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.function.Function; +import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -38,6 +39,11 @@ */ public class GRpcDocBuildTemplate implements IDocBuildTemplate, IRpcDocTemplate { + /** + * Logger for the class. + */ + Logger log = Logger.getLogger(GRpcDocBuildTemplate.class.getName()); + /** * api index */ @@ -241,7 +247,7 @@ private Set findProtoFilesRecursively(String directoryPath) { .collect(Collectors.toSet()); } catch (IOException e) { - System.err.println("Error walking directory: " + directoryPath + ", " + e.getMessage()); + log.warning("Error walking directory: " + directoryPath + ", " + e.getMessage()); return Collections.emptySet(); } } @@ -271,7 +277,7 @@ private void copyResourceFile(String resourcePath, String targetPath) { FileUtil.copyInputStreamToFile(resourceAsStream, new File(targetPath), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { - System.err.println("Error executing command error:" + e.getMessage()); + log.warning("Error executing command error:" + e.getMessage()); } } @@ -301,7 +307,7 @@ private void executeCommand(List command, ProtoInfo protoInfo) { } } catch (IOException e) { - System.err.println("Failed to grant execute permission: " + e.getMessage()); + log.warning("Failed to grant execute permission: " + e.getMessage()); return; } @@ -311,7 +317,7 @@ private void executeCommand(List command, ProtoInfo protoInfo) { try { Process process = processBuilder.start(); - StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), System.err::println); + StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), message -> log.warning(message)); Thread outputThread = new Thread(outputGobbler); outputThread.start(); @@ -321,11 +327,11 @@ private void executeCommand(List command, ProtoInfo protoInfo) { outputThread.join(); if (exitCode != 0) { - System.err.println("Error executing command for files"); + log.warning("Error executing command for files"); } } catch (IOException | InterruptedException e) { - System.err.println("Error executing command: " + e.getMessage()); + log.warning("Error executing command: " + e.getMessage()); } } diff --git a/src/main/java/com/ly/doc/template/IWebSocketDocBuildTemplate.java b/src/main/java/com/ly/doc/template/IWebSocketDocBuildTemplate.java index 1e9fc10c..4e060607 100644 --- a/src/main/java/com/ly/doc/template/IWebSocketDocBuildTemplate.java +++ b/src/main/java/com/ly/doc/template/IWebSocketDocBuildTemplate.java @@ -49,9 +49,9 @@ default List getWebSocketData(ProjectDocConfigBuilder projectBuilder) { preRender(docBuildHelper); - Collection candidateClasses = getCandidateClasses(projectBuilder, docBuildHelper); + Collection candidateClasses = this.getCandidateClasses(projectBuilder, docBuildHelper); - return renderWebSocketApi(projectBuilder, candidateClasses); + return this.renderWebSocketApi(projectBuilder, candidateClasses); } /** diff --git a/src/main/java/com/ly/doc/template/IWebSocketTemplate.java b/src/main/java/com/ly/doc/template/IWebSocketTemplate.java index 2b7b35ef..608c3670 100644 --- a/src/main/java/com/ly/doc/template/IWebSocketTemplate.java +++ b/src/main/java/com/ly/doc/template/IWebSocketTemplate.java @@ -28,7 +28,6 @@ import com.ly.doc.handler.DefaultWebSocketRequestHandler; import com.ly.doc.handler.IWebSocketRequestHandler; import com.ly.doc.model.ApiConfig; -import com.ly.doc.model.ApiDoc; import com.ly.doc.model.ApiParam; import com.ly.doc.model.WebSocketDoc; import com.ly.doc.model.annotation.FrameworkAnnotations; @@ -39,7 +38,10 @@ import com.ly.doc.utils.JavaClassUtil; import com.power.common.util.StringUtil; import com.power.common.util.ValidateUtil; -import com.thoughtworks.qdox.model.*; +import com.thoughtworks.qdox.model.JavaAnnotation; +import com.thoughtworks.qdox.model.JavaClass; +import com.thoughtworks.qdox.model.JavaMethod; +import com.thoughtworks.qdox.model.JavaParameter; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -87,6 +89,12 @@ default List processWebSocketData(ProjectDocConfigBuilder projectB if (Objects.nonNull(javaClass.getTagByName(DocTags.IGNORE))) { continue; } + // if the class is websocket + Optional optionalAnnotation = this.getOptionalWebSocketAnnotation(javaClass, + frameworkAnnotations); + if (!optionalAnnotation.isPresent()) { + continue; + } String strOrder = JavaClassUtil.getClassTagsValue(javaClass, DocTags.ORDER, Boolean.TRUE); int order = 0; if (ValidateUtil.isNonNegativeInteger(strOrder)) { @@ -95,7 +103,7 @@ default List processWebSocketData(ProjectDocConfigBuilder projectB maxOrder = Math.max(maxOrder, order); } WebSocketDoc webSocketDoc = this.buildEntryPointWebSocketDoc(javaClass, apiConfig, webSocketRequestHandler, - frameworkAnnotations, order); + order, optionalAnnotation.get()); if (Objects.nonNull(webSocketDoc)) { apiDocList.add(webSocketDoc); } @@ -115,6 +123,9 @@ else if (setCustomOrder) { }); return tempList.stream().sorted(Comparator.comparing(WebSocketDoc::getOrder)).collect(Collectors.toList()); } + else { + apiDocList.forEach(p -> p.setOrder(ATOMIC_INTEGER.getAndAdd(1))); + } return apiDocList; } @@ -123,23 +134,17 @@ else if (setCustomOrder) { * @param javaClass JavaClass * @param apiConfig ApiConfig * @param webSocketRequestHandler WebSocketRequestHandler - * @param frameworkAnnotations FrameworkAnnotations * @param order order + * @param serverEndpointAnnotation ServerEndpointAnnotation * @return WebSocketDoc */ default WebSocketDoc buildEntryPointWebSocketDoc(final JavaClass javaClass, ApiConfig apiConfig, - IWebSocketRequestHandler webSocketRequestHandler, FrameworkAnnotations frameworkAnnotations, int order) { - // if the class is websocket - Optional optionalAnnotation = this.getOptionalWebSocketAnnotation(javaClass, - frameworkAnnotations); - if (!optionalAnnotation.isPresent()) { - return null; - } + IWebSocketRequestHandler webSocketRequestHandler, int order, JavaAnnotation serverEndpointAnnotation) { webSocketRequestHandler = webSocketRequestHandler == null ? DefaultWebSocketRequestHandler.getInstance() : webSocketRequestHandler; ServerEndpoint serverEndpoint = webSocketRequestHandler.handleServerEndpoint(javaClass, - optionalAnnotation.get()); + serverEndpointAnnotation); WebSocketDoc webSocketDoc = new WebSocketDoc(); // if it does not have subProtocols @@ -153,7 +158,7 @@ default WebSocketDoc buildEntryPointWebSocketDoc(final JavaClass javaClass, ApiC } // build websocket doc webSocketDoc.setName(javaClass.getName()); - webSocketDoc.setUrl(replaceHttpPrefixToWebSocketPrefix(apiConfig.getServerUrl()) + serverEndpoint.getUrl()); + webSocketDoc.setUri(replaceHttpPrefixToWebSocketPrefix(apiConfig.getServerUrl()) + serverEndpoint.getUrl()); webSocketDoc.setPackageName(javaClass.getPackage().getName()); webSocketDoc.setDesc(DocUtil.getEscapeAndCleanComment(javaClass.getComment())); webSocketDoc.setAuthor(JavaClassUtil.getClassTagsValue(javaClass, DocTags.AUTHOR, Boolean.TRUE)); diff --git a/src/main/java/com/ly/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/ly/doc/template/SpringBootDocBuildTemplate.java index 24cf3e27..41fd693a 100644 --- a/src/main/java/com/ly/doc/template/SpringBootDocBuildTemplate.java +++ b/src/main/java/com/ly/doc/template/SpringBootDocBuildTemplate.java @@ -68,7 +68,7 @@ public ApiSchema renderApi(ProjectDocConfigBuilder projectBuilder, Colle public List renderWebSocketApi(ProjectDocConfigBuilder projectBuilder, Collection candidateClasses) { FrameworkAnnotations frameworkAnnotations = registeredAnnotations(); - return processWebSocketData(projectBuilder, frameworkAnnotations, new SpringMVCRequestMappingHandler(), + return this.processWebSocketData(projectBuilder, frameworkAnnotations, new SpringMVCRequestMappingHandler(), candidateClasses); } diff --git a/src/main/resources/template/WebSocket.md b/src/main/resources/template/WebSocket.md deleted file mode 100644 index 4a1daf84..00000000 --- a/src/main/resources/template/WebSocket.md +++ /dev/null @@ -1,32 +0,0 @@ -<%if(isNotEmpty(projectName)){%> -# ${projectName} -<%}%> -<% -for(doc in webSocketDocList){ -%> -<%if(doc.deprecated){%> -### ~~${htmlEscape(doc.desc)}~~ -<%}else{%> -### ${htmlEscape(doc.desc)} -<%}%> -**URL:** ${doc.url} - -**Author:** ${doc.author} - -**Description:** ${doc.desc} - -**SubProtocols:** ${doc.subProtocols} - -<%if(isNotEmpty(doc.pathParams)){%> - -**Path-parameters:** - -| Parameter | Type | Required | Description | Since | -|-----------|------|----------|-------------|-------| -<% -for(param in doc.pathParams){ -%> -|${param.field}|${param.type}|${param.required}|${lineBreaksToBr(param.desc)}|${param.version}| -<%}%> -<%}%> -<%}%> \ No newline at end of file diff --git a/src/main/resources/template/grpc/Grpc.md b/src/main/resources/template/grpc/Grpc.md new file mode 100644 index 00000000..eda45caf --- /dev/null +++ b/src/main/resources/template/grpc/Grpc.md @@ -0,0 +1,53 @@ +# ${htmlEscape(desc)} + +**URI:** ${uri} + +**Service:** ${name} + +**Protocol:** ${protocol} + +**Author:** ${author} + +**Version:** ${version} +<% for(doc in list){ %> +<%if(doc.deprecated){%> + +## ~~${htmlEscape(doc.desc)}~~ + +<%}else{%> + +## ${htmlEscape(doc.desc)} + +<%}%> + +**Definition:** ${doc.escapeMethodDefinition} + +<%if(isNotEmpty(doc.author)){%> +**Author:** ${doc.author} +<%}%> + +**Description:** ${doc.detail} + +**MethodType:** ${doc.methodType} + +<%if(isNotEmpty(doc.requestParams)){%> +**Invoke-parameters:** + +| Parameter | Type | Required | Description | Since | +|-----------|------|----------|-------------|-------| +<% for(param in doc.requestParams){ %> +|${param.field}|${htmlEscape(param.type)}|${param.required}|${lineBreaksToBr(param.desc)}|${param.version}| +<%}%> +<%}%> + +<%if(isNotEmpty(doc.responseParams)){%> +**Response-fields:** + +| Field | Type | Description | Since | +|-------|------|-------------|-------| +<% for(param in doc.responseParams){ %> +|${param.field}|${htmlEscape(param.type)}|${lineBreaksToBr(param.desc)}|${param.version}| +<%}%> +<%}%> + +<%}%> \ No newline at end of file diff --git a/src/main/resources/template/grpc/GrpcAllInOne.html b/src/main/resources/template/grpc/GrpcAllInOne.html index e74c433f..ef8225ca 100644 --- a/src/main/resources/template/grpc/GrpcAllInOne.html +++ b/src/main/resources/template/grpc/GrpcAllInOne.html @@ -1 +1 @@ -<%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}. ${htmlEscape(api.desc)}

URI: ${api.uri}

Service: ${api.name}

Protocol: ${api.protocol}

Author: ${api.author}

Version: ${api.version}

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

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

Definition: ${doc.escapeMethodDefinition}

Description: ${doc.detail}

MethodType: ${doc.methodType}

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

Invoke-parameters:

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

${param.field}

${htmlEscape(param.type)}

${param.desc}

${param.required}

${param.version}

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

Response-fields:

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

${param.field}

${htmlEscape(param.type)}

${param.desc}

${param.version}

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

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

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

${error.value}

${htmlEscape(error.desc)}

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

${dictListOrder}. ${dictListTitle}

<%for(dict in dictList){%>

${dictListOrder}.${dict.order}. ${htmlEscape(dict.title)}

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

${dataDict.name}

${dataDict.value}

${dataDict.type}

${htmlEscape(dataDict.desc)}

<%}%>
<%}%>
Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github
Top
\ No newline at end of file +<%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}. ${htmlEscape(api.desc)}

URI: ${api.uri}

Service: ${api.name}

Protocol: ${api.protocol}

Author: ${api.author}

Version: ${api.version}

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

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

Definition: ${doc.escapeMethodDefinition}

Description: ${doc.detail}

MethodType: ${doc.methodType}

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

Invoke-parameters:

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

${param.field}

${htmlEscape(param.type)}

${param.desc}

${param.required}

${param.version}

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

Response-fields:

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

${param.field}

${htmlEscape(param.type)}

${param.desc}

${param.version}

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

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

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

${error.value}

${htmlEscape(error.desc)}

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

${apiDocList.~size+2}. ${dictListTitle}

<%for(dict in dictList){%>

${apiDocList.~size+2}.${dict.order}. ${htmlEscape(dict.title)}

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

${dataDict.name}

${dataDict.value}

${dataDict.type}

${htmlEscape(dataDict.desc)}

<%}%>
<%}%>
Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github
Top
\ No newline at end of file diff --git a/src/main/resources/template/grpc/GrpcSearch.btl b/src/main/resources/template/grpc/GrpcSearch.btl index 40c1422c..b84bf294 100644 --- a/src/main/resources/template/grpc/GrpcSearch.btl +++ b/src/main/resources/template/grpc/GrpcSearch.btl @@ -3,7 +3,6 @@ let api = []; api.push({ alias: '${api.alias}', order: '${api.order}', - link: '${api.link}', desc: '${api.desc}', list: [] }) @@ -29,7 +28,6 @@ function keyDownSearch(e) { searchArr.push({ order: apiData.order, desc: apiData.desc, - link: apiData.link, list: apiData.list }); } else { @@ -47,7 +45,6 @@ function keyDownSearch(e) { const data = { order: apiData.order, desc: apiData.desc, - link: apiData.link, list: methodListTemp }; searchArr.push(data); @@ -91,7 +88,7 @@ function buildAccordion(apiData, liClass, display) { if (apiData.length > 0) { for (let j = 0; j < apiData.length; j++) { html += '
  • '; - html += '' + apiData[j].order + '. ' + apiData[j].desc + ''; + html += '' + apiData[j].order + '. ' + apiData[j].desc + ''; html += '
      '; doc = apiData[j].list; for (let m = 0; m < doc.length; m++) { diff --git a/src/main/resources/template/websocket/WebSocket.adoc b/src/main/resources/template/websocket/WebSocket.adoc new file mode 100644 index 00000000..a0511fb5 --- /dev/null +++ b/src/main/resources/template/websocket/WebSocket.adoc @@ -0,0 +1,24 @@ += ${desc} + +*URI:* ${uri} + +*Author:* ${author} + +*Description:* ${desc} + +*SubProtocols:* ${subProtocols} + +<%if(isNotEmpty(pathParams)){%> +*Path-parameters:* +[width="100%",options="header"] +[stripes=even] +|==================== +|Parameter | Type |Required|Description |Since +<% +for(param in pathParams){ +%> +|${param.field} |${param.type} |${param.required}|${htmlEscape(param.desc)}|${param.version} +<%}%> +|==================== + +<%}%> \ No newline at end of file diff --git a/src/main/resources/template/websocket/WebSocket.md b/src/main/resources/template/websocket/WebSocket.md new file mode 100644 index 00000000..e7bf21d9 --- /dev/null +++ b/src/main/resources/template/websocket/WebSocket.md @@ -0,0 +1,25 @@ +<%if(deprecated){%> +# ~~${htmlEscape(desc)}~~ +<%}else{%> +# ${htmlEscape(desc)} +<%}%> +**URL:** ${uri} + +**Author:** ${author} + +**Description:** ${desc} + +**SubProtocols:** ${subProtocols} + +<%if(isNotEmpty(pathParams)){%> + +**Path-parameters:** + +| Parameter | Type | Required | Description | Since | +|-----------|------|----------|-------------|-------| +<% +for(param in pathParams){ +%> +|${param.field}|${param.type}|${param.required}|${lineBreaksToBr(param.desc)}|${param.version}| +<%}%> +<%}%> \ No newline at end of file diff --git a/src/main/resources/template/websocket/WebSocketAllInOne.adoc b/src/main/resources/template/websocket/WebSocketAllInOne.adoc new file mode 100644 index 00000000..02bd28cc --- /dev/null +++ b/src/main/resources/template/websocket/WebSocketAllInOne.adoc @@ -0,0 +1,80 @@ +<%if(isNotEmpty(projectName)){%> ${projectName} +<%}%> + +[width="100%",options="header"] +[stripes=even] +<%if(isNotEmpty(revisionLogList)){%> + +|==================== +|Version |Update Time |Status | Author |Description +<% for(revisionLog in revisionLogList){ %> +|${revisionLog.version} |${revisionLog.revisionTime} |${revisionLog.status} |${revisionLog.author} |${revisionLog.remarks} +<%}%> +|==================== + +<%}%> +<% for(doc in webSocketDocList){ +%> + +== ${htmlEscape(doc.desc)} + +*URI:* ${doc.uri} + +**Author:** ${doc.author} + +**Description:** ${doc.desc} + +**SubProtocols:** ${doc.subProtocols} + +<%if(isNotEmpty(doc.pathParams)){%> +*Path-parameters:* + +[width="100%",options="header"] +[stripes=even] +|==================== +|Parameter | Type |Required|Description |Since +<% +for(param in doc.pathParams){ +%> +|${param.field} |${param.type} |${param.required}|${htmlEscape(param.desc)}|${param.version} +<%}%> +|==================== + +<%}%> <%}%> +<%if(isNotEmpty(errorCodeList)){%> +${errorListTitle} + +[width="100%",options="header"] +[stripes=even] + +|==================== +|Error code |Description +<% for(error in errorCodeList){ %> + + +|${error.value} |${htmlEscape(error.desc)} +<%}%> +|==================== + + +<%}%> + +<%if(isNotEmpty(dictList)){ %> +${dictListTitle} + +<% for(dict in dictList){ +%> +[width="100%",options="header"] +[stripes=even] + +${dict.title} +|==================== +|Name |Code |Type |Description +<% for(dataDict in dict.dataDictList){%> +|${dataDict.name} |${dataDict.value} |${dataDict.type} |${htmlEscape(dataDict.desc)} +<%}%> +|==================== + +<%}%> + +<%}%> diff --git a/src/main/resources/template/websocket/WebSocketAllInOne.html b/src/main/resources/template/websocket/WebSocketAllInOne.html new file mode 100644 index 00000000..4a63dfe1 --- /dev/null +++ b/src/main/resources/template/websocket/WebSocketAllInOne.html @@ -0,0 +1 @@ +<%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 webSocketDocList){%>

      ${api.order}. ${htmlEscape(api.desc)}

      URI: ${api.uri}

      Author: ${api.author}

      Description: ${api.desc}

      SubProtocols: ${api.subProtocols}

      <%if(isNotEmpty(api.pathParams)){%>

      Path-parameters:

      ParameterTypeDescriptionRequiredSince
      <%}%><%}%><%if(isNotEmpty(errorCodeList)){%>

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

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

      ${error.value}

      ${htmlEscape(error.desc)}

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

      ${webSocketDocList.~size+2}. ${dictListTitle}

      <%for(dict in dictList){%>

      ${webSocketDocList.~size+2}.${dict.order}. ${htmlEscape(dict.title)}

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

      ${dataDict.name}

      ${dataDict.value}

      ${dataDict.type}

      ${htmlEscape(dataDict.desc)}

      <%}%>
      <%}%>
      Generated by smart-doc at ${createTime}Suggestions,contact,support and error reporting on Gitee or Github
      Top
      \ No newline at end of file diff --git a/src/main/resources/template/websocket/WebSocketAllOne.md b/src/main/resources/template/websocket/WebSocketAllOne.md new file mode 100644 index 00000000..7847d80b --- /dev/null +++ b/src/main/resources/template/websocket/WebSocketAllOne.md @@ -0,0 +1,71 @@ +<%if(isNotEmpty(projectName)){%> +# ${projectName} +<%}%> + +<%if(isNotEmpty(revisionLogList)){%> + +| Version | Update Time | Status | Author | Description | +|---------|-------------|--------|--------|-------------| +<% for(revisionLog in revisionLogList){ %> +|${revisionLog.version} |${revisionLog.revisionTime} |${revisionLog.status} |${revisionLog.author} |${lineBreaksToBr(revisionLog.remarks)}| +<%}%> + +<%}%> + +<% +for(doc in webSocketDocList){ +%> +<%if(doc.deprecated){%> +## ~~${htmlEscape(doc.desc)}~~ +<%}else{%> +## ${htmlEscape(doc.desc)} +<%}%> +**URI:** ${doc.uri} + +**Author:** ${doc.author} + +**Description:** ${doc.desc} + +**SubProtocols:** ${doc.subProtocols} + +<%if(isNotEmpty(doc.pathParams)){%> + +**Path-parameters:** + +| Parameter | Type | Required | Description | Since | +|-----------|------|----------|-------------|-------| +<% +for(param in doc.pathParams){ +%> +|${param.field}|${param.type}|${param.required}|${lineBreaksToBr(param.desc)}|${param.version}| +<%}%> +<%}%> +<%}%> +<%if(isNotEmpty(errorCodeList)){%> + +## ${errorListTitle} + +| Error code | Description | +|------------|-------------| +<% for(error in errorCodeList){ %> +|${error.value}|${htmlEscape(error.desc)}| +<%}%> + +<%}%> + +<%if(isNotEmpty(dictList)){%> + +## ${dictListTitle} + +<% for(dict in dictList){ %> + +### ${dict.title} + +| Name | Code | Type | Description | +|-----|------|------|-------------| +<% for(dataDict in dict.dataDictList){ %> +|${dataDict.name}|${dataDict.value}|${dataDict.type}|${htmlEscape(dataDict.desc)}| +<%}%> + +<%}%> +<%}%> diff --git a/src/main/resources/template/websocket/WebSocketSearch.btl b/src/main/resources/template/websocket/WebSocketSearch.btl new file mode 100644 index 00000000..e7533aac --- /dev/null +++ b/src/main/resources/template/websocket/WebSocketSearch.btl @@ -0,0 +1,94 @@ +let api = []; +<%for(api in directoryTree){%> +api.push({ + alias: '${api.alias}', + order: '${api.order}', + desc: '${api.desc}', + uri: '${api.uri}', +}) +<%}%> +document.onkeydown = keyDownSearch; +function keyDownSearch(e) { + const theEvent = e; + const code = theEvent.keyCode || theEvent.which || theEvent.charCode; + if (code == 13) { + const search = document.getElementById('search'); + const searchValue = search.value; + let searchArr = []; + for (let i = 0; i < api.length; i++) { + let apiData = api[i]; + const desc = apiData.desc; + if (desc.indexOf(searchValue) > -1) { + searchArr.push({ + order: apiData.order, + desc: apiData.desc, + }); + } else { + let methodList = apiData.list || []; + let methodListTemp = []; + for (let j = 0; j < methodList.length; j++) { + const methodData = methodList[j]; + const methodDesc = methodData.desc; + if (methodDesc.indexOf(searchValue) > -1) { + methodListTemp.push(methodData); + break; + } + } + if (methodListTemp.length > 0) { + const data = { + order: apiData.order, + desc: apiData.desc, + }; + searchArr.push(data); + } + } + } + let html; + if (searchValue == '') { + const liClass = ""; + const display = "display: none"; + html = buildAccordion(api,liClass,display); + document.getElementById('accordion').innerHTML = html; + } else { + const liClass = "open"; + const display = "display: block"; + html = buildAccordion(searchArr,liClass,display); + document.getElementById('accordion').innerHTML = html; + } + 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; + $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); + } +} + +function buildAccordion(apiData, liClass, display) { + let html = ""; + let doc; + if (apiData.length > 0) { + for (let j = 0; j < apiData.length; j++) { + html += '
    • '; + html += '' + apiData[j].order + '. ' + apiData[j].desc + ''; + html += ''; + html += '
    • '; + } + } + return html; +} \ No newline at end of file