optimized cod
This commit is contained in:
parent
d0d3416f74
commit
05cef3879d
4
pom.xml
4
pom.xml
|
@ -32,7 +32,7 @@
|
|||
</developers>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<flexmark.version>0.60.2</flexmark.version>
|
||||
<flexmark.version>0.61.32</flexmark.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -44,7 +44,7 @@
|
|||
<dependency>
|
||||
<groupId>com.ibeetl</groupId>
|
||||
<artifactId>beetl</artifactId>
|
||||
<version>3.1.1.RELEASE</version>
|
||||
<version>3.1.6.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.qdox</groupId>
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
/*
|
||||
* smart-doc https://github.com/shalousun/smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 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.power.doc.builder;
|
||||
|
||||
import com.power.common.util.CollectionUtil;
|
||||
|
@ -19,6 +41,7 @@ import java.util.Objects;
|
|||
* @author yu 2020/5/16.
|
||||
*/
|
||||
public class BaseDocBuilderTemplate {
|
||||
|
||||
/**
|
||||
* check condition and init
|
||||
*
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
package com.power.doc.builder;
|
||||
|
||||
import com.power.common.util.*;
|
||||
import com.power.doc.constants.DocGlobalConstants;
|
||||
import com.power.doc.constants.DocLanguage;
|
||||
import com.power.doc.constants.TemplateVariable;
|
||||
import com.power.doc.model.*;
|
||||
import com.power.doc.template.IDocBuildTemplate;
|
||||
|
@ -44,40 +42,10 @@ import static com.power.doc.constants.DocGlobalConstants.FILE_SEPARATOR;
|
|||
/**
|
||||
* @author yu 2019/9/26.
|
||||
*/
|
||||
public class DocBuilderTemplate {
|
||||
public class DocBuilderTemplate extends BaseDocBuilderTemplate {
|
||||
|
||||
private static long now = System.currentTimeMillis();
|
||||
|
||||
/**
|
||||
* check condition and init
|
||||
*
|
||||
* @param config Api config
|
||||
*/
|
||||
public void checkAndInit(ApiConfig config) {
|
||||
this.checkAndInitForGetApiData(config);
|
||||
if (StringUtil.isEmpty(config.getOutPath())) {
|
||||
throw new RuntimeException("doc output path can't be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check condition and init for get Data
|
||||
*
|
||||
* @param config Api config
|
||||
*/
|
||||
public void checkAndInitForGetApiData(ApiConfig config) {
|
||||
if (null == config) {
|
||||
throw new NullPointerException("ApiConfig can't be null");
|
||||
}
|
||||
if (null != config.getLanguage()) {
|
||||
System.setProperty(DocGlobalConstants.DOC_LANGUAGE, config.getLanguage().getCode());
|
||||
} else {
|
||||
//default is chinese
|
||||
config.setLanguage(DocLanguage.CHINESE);
|
||||
System.setProperty(DocGlobalConstants.DOC_LANGUAGE, DocLanguage.CHINESE.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get all api data
|
||||
*
|
||||
|
@ -179,20 +147,6 @@ public class DocBuilderTemplate {
|
|||
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + outPutFileName);
|
||||
}
|
||||
|
||||
private void setDirectoryLanguageVariable(ApiConfig config, Template mapper) {
|
||||
if (null != config.getLanguage()) {
|
||||
if (DocLanguage.CHINESE.code.equals(config.getLanguage().getCode())) {
|
||||
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
|
||||
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
|
||||
} else {
|
||||
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_EN_TITLE);
|
||||
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_EN_TITLE);
|
||||
}
|
||||
} else {
|
||||
mapper.binding(TemplateVariable.ERROR_LIST_TITLE.getVariable(), DocGlobalConstants.ERROR_CODE_LIST_CN_TITLE);
|
||||
mapper.binding(TemplateVariable.DICT_LIST_TITLE.getVariable(), DocGlobalConstants.DICT_CN_TITLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a single controller api document
|
||||
|
@ -205,7 +159,7 @@ public class DocBuilderTemplate {
|
|||
public void buildSingleApi(ProjectDocConfigBuilder projectBuilder, String controllerName, String template, String fileExtension) {
|
||||
ApiConfig config = projectBuilder.getApiConfig();
|
||||
FileUtil.mkdirs(config.getOutPath());
|
||||
IDocBuildTemplate docBuildTemplate = new SpringBootDocBuildTemplate();
|
||||
IDocBuildTemplate<ApiDoc> docBuildTemplate = new SpringBootDocBuildTemplate();
|
||||
ApiDoc doc = docBuildTemplate.getSingleApiData(projectBuilder, controllerName);
|
||||
Template mapper = BeetlTemplateUtil.getByName(template);
|
||||
mapper.binding(TemplateVariable.DESC.getVariable(), doc.getDesc());
|
||||
|
@ -259,35 +213,6 @@ public class DocBuilderTemplate {
|
|||
return apiDocDictList;
|
||||
}
|
||||
|
||||
private List<ApiErrorCode> errorCodeDictToList(ApiConfig config) {
|
||||
if (CollectionUtil.isNotEmpty(config.getErrorCodes())) {
|
||||
return config.getErrorCodes();
|
||||
}
|
||||
List<ApiErrorCodeDictionary> errorCodeDictionaries = config.getErrorCodeDictionaries();
|
||||
if (CollectionUtil.isEmpty(errorCodeDictionaries)) {
|
||||
return new ArrayList<>(0);
|
||||
} else {
|
||||
List<ApiErrorCode> errorCodeList = new ArrayList<>();
|
||||
try {
|
||||
for (ApiErrorCodeDictionary dictionary : errorCodeDictionaries) {
|
||||
Class<?> clzz = dictionary.getEnumClass();
|
||||
if (Objects.isNull(clzz)) {
|
||||
if (StringUtil.isEmpty(dictionary.getEnumClassName())) {
|
||||
throw new RuntimeException(" enum class name can't be null.");
|
||||
}
|
||||
clzz = Class.forName(dictionary.getEnumClassName());
|
||||
}
|
||||
List<ApiErrorCode> enumDictionaryList = EnumUtil.getEnumInformation(clzz, dictionary.getCodeField(),
|
||||
dictionary.getDescField());
|
||||
errorCodeList.addAll(enumDictionaryList);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return errorCodeList;
|
||||
}
|
||||
}
|
||||
|
||||
private List<ApiDoc> listOfApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) {
|
||||
this.checkAndInitForGetApiData(config);
|
||||
config.setMd5EncryptedHtmlName(true);
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
/*
|
||||
* smart-doc https://github.com/shalousun/smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 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.power.doc.builder.rpc;
|
||||
|
||||
import com.power.doc.builder.ProjectDocConfigBuilder;
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.template.JavaDocBuildTemplate;
|
||||
import com.power.doc.template.RpcDocBuildTemplate;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -40,7 +62,7 @@ public class RpcAdocBuilder {
|
|||
RpcDocBuilderTemplate builderTemplate = new RpcDocBuilderTemplate();
|
||||
builderTemplate.checkAndInit(config);
|
||||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
|
||||
JavaDocBuildTemplate docBuildTemplate = new JavaDocBuildTemplate();
|
||||
RpcDocBuildTemplate docBuildTemplate = new RpcDocBuildTemplate();
|
||||
List<RpcApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
|
||||
if (config.isAllInOne()) {
|
||||
builderTemplate.buildAllInOne(apiDocList, config, javaProjectBuilder, RPC_ALL_IN_ONE_ADOC_TPL, INDEX_DOC);
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* smart-doc https://github.com/shalousun/smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 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.power.doc.builder.rpc;
|
||||
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.rpc.RpcApiAllData;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
|
||||
/**
|
||||
* @author yu 2020/5/24.
|
||||
*/
|
||||
public class RpcApiDataBuilder {
|
||||
|
||||
/**
|
||||
* Get list of ApiDoc
|
||||
*
|
||||
* @param config ApiConfig
|
||||
* @return List of ApiDoc
|
||||
*/
|
||||
public static RpcApiAllData getApiData(ApiConfig config) {
|
||||
RpcDocBuilderTemplate builderTemplate = new RpcDocBuilderTemplate();
|
||||
builderTemplate.checkAndInitForGetApiData(config);
|
||||
JavaProjectBuilder javaProjectBuilder = new JavaProjectBuilder();
|
||||
builderTemplate.getApiData(config, javaProjectBuilder);
|
||||
return builderTemplate.getApiData(config, javaProjectBuilder);
|
||||
}
|
||||
}
|
|
@ -1,13 +1,40 @@
|
|||
/*
|
||||
* smart-doc https://github.com/shalousun/smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 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.power.doc.builder.rpc;
|
||||
|
||||
import com.power.common.util.DateTimeUtil;
|
||||
import com.power.common.util.FileUtil;
|
||||
import com.power.doc.builder.BaseDocBuilderTemplate;
|
||||
import com.power.doc.builder.ProjectDocConfigBuilder;
|
||||
import com.power.doc.constants.TemplateVariable;
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.ApiErrorCode;
|
||||
import com.power.doc.model.rpc.RpcApiAllData;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.template.IDocBuildTemplate;
|
||||
import com.power.doc.template.RpcDocBuildTemplate;
|
||||
import com.power.doc.utils.BeetlTemplateUtil;
|
||||
import com.power.doc.utils.DocUtil;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
import org.beetl.core.Template;
|
||||
|
||||
|
@ -85,4 +112,31 @@ public class RpcDocBuilderTemplate extends BaseDocBuilderTemplate {
|
|||
FileUtil.nioWriteFile(mapper.render(), config.getOutPath() + FILE_SEPARATOR + outPutFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* get all api data
|
||||
*
|
||||
* @param config ApiConfig
|
||||
* @param javaProjectBuilder JavaProjectBuilder
|
||||
* @return ApiAllData
|
||||
*/
|
||||
public RpcApiAllData getApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) {
|
||||
RpcApiAllData apiAllData = new RpcApiAllData();
|
||||
apiAllData.setProjectName(config.getProjectName());
|
||||
apiAllData.setProjectId(DocUtil.generateId(config.getProjectName()));
|
||||
apiAllData.setLanguage(config.getLanguage().getCode());
|
||||
apiAllData.setApiDocList(listOfApiData(config, javaProjectBuilder));
|
||||
apiAllData.setErrorCodeList(errorCodeDictToList(config));
|
||||
apiAllData.setRevisionLogs(config.getRevisionLogs());
|
||||
apiAllData.setDependencyList(config.getRpcApiDependencies());
|
||||
return apiAllData;
|
||||
}
|
||||
|
||||
private List<RpcApiDoc> listOfApiData(ApiConfig config, JavaProjectBuilder javaProjectBuilder) {
|
||||
this.checkAndInitForGetApiData(config);
|
||||
config.setMd5EncryptedHtmlName(true);
|
||||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
|
||||
IDocBuildTemplate docBuildTemplate = new RpcDocBuildTemplate();
|
||||
return docBuildTemplate.getApiData(configBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
/*
|
||||
* smart-doc https://github.com/shalousun/smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 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.power.doc.builder.rpc;
|
||||
|
||||
import com.power.common.util.CollectionUtil;
|
||||
|
@ -10,7 +32,7 @@ import com.power.doc.model.ApiConfig;
|
|||
import com.power.doc.model.ApiErrorCode;
|
||||
import com.power.doc.model.rpc.RpcApiDependency;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.template.JavaDocBuildTemplate;
|
||||
import com.power.doc.template.RpcDocBuildTemplate;
|
||||
import com.power.doc.utils.BeetlTemplateUtil;
|
||||
import com.power.doc.utils.MarkDownUtil;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
|
@ -24,6 +46,7 @@ import static com.power.doc.constants.DocGlobalConstants.*;
|
|||
* @author yu 2020/5/17.
|
||||
*/
|
||||
public class RpcHtmlBuilder {
|
||||
|
||||
private static long now = System.currentTimeMillis();
|
||||
|
||||
private static String INDEX_HTML = "rpc-index.html";
|
||||
|
@ -50,7 +73,7 @@ public class RpcHtmlBuilder {
|
|||
builderTemplate.checkAndInit(config);
|
||||
builderTemplate.checkAndInit(config);
|
||||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
|
||||
JavaDocBuildTemplate docBuildTemplate = new JavaDocBuildTemplate();
|
||||
RpcDocBuildTemplate docBuildTemplate = new RpcDocBuildTemplate();
|
||||
List<RpcApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
|
||||
if (config.isAllInOne()) {
|
||||
Template indexCssTemplate = BeetlTemplateUtil.getByName(ALL_IN_ONE_CSS);
|
||||
|
@ -167,7 +190,7 @@ public class RpcHtmlBuilder {
|
|||
private static void buildDependency(List<RpcApiDependency> apiDocDictList, String outPath) {
|
||||
if (CollectionUtil.isNotEmpty(apiDocDictList)) {
|
||||
Template template = BeetlTemplateUtil.getByName(RPC_DEPENDENCY_MD_TPL);
|
||||
template.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList);
|
||||
template.binding(TemplateVariable.DEPENDENCY_LIST.getVariable(), apiDocDictList);
|
||||
String dictHtml = MarkDownUtil.toHtml(template.render());
|
||||
Template dictTpl = BeetlTemplateUtil.getByName(HTML_API_DOC_TPL);
|
||||
dictTpl.binding(TemplateVariable.VERSION.getVariable(), now);
|
||||
|
|
|
@ -1,10 +1,33 @@
|
|||
/*
|
||||
* smart-doc https://github.com/shalousun/smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 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.power.doc.builder.rpc;
|
||||
|
||||
import com.power.common.util.DateTimeUtil;
|
||||
import com.power.doc.builder.ProjectDocConfigBuilder;
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.template.JavaDocBuildTemplate;
|
||||
import com.power.doc.template.IDocBuildTemplate;
|
||||
import com.power.doc.template.RpcDocBuildTemplate;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -39,7 +62,7 @@ public class RpcMarkdownBuilder {
|
|||
RpcDocBuilderTemplate builderTemplate = new RpcDocBuilderTemplate();
|
||||
builderTemplate.checkAndInit(config);
|
||||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
|
||||
JavaDocBuildTemplate docBuildTemplate = new JavaDocBuildTemplate();
|
||||
IDocBuildTemplate docBuildTemplate = new RpcDocBuildTemplate();
|
||||
List<RpcApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
|
||||
if (config.isAllInOne()) {
|
||||
String version = config.isCoverOld() ? "" : "-V" + DateTimeUtil.long2Str(System.currentTimeMillis(), DATE_FORMAT);
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* smart-doc https://github.com/shalousun/smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 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.power.doc.model.rpc;
|
||||
|
||||
import com.power.doc.model.ApiDocDict;
|
||||
import com.power.doc.model.ApiErrorCode;
|
||||
import com.power.doc.model.RevisionLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yu 2020/5/24.
|
||||
*/
|
||||
public class RpcApiAllData {
|
||||
|
||||
/**
|
||||
* project name
|
||||
*/
|
||||
private String projectName;
|
||||
|
||||
/**
|
||||
* project id
|
||||
*/
|
||||
private String projectId;
|
||||
|
||||
/**
|
||||
* docLanguage
|
||||
*/
|
||||
private String language;
|
||||
|
||||
/**
|
||||
* doc list
|
||||
*/
|
||||
private List<RpcApiDoc> apiDocList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private List<ApiDocDict> apiDocDictList;
|
||||
|
||||
/**
|
||||
* error code list
|
||||
*/
|
||||
private List<ApiErrorCode> errorCodeList;
|
||||
|
||||
/**
|
||||
* List of change log
|
||||
*/
|
||||
private List<RevisionLog> revisionLogs;
|
||||
|
||||
/**
|
||||
* list of dependency
|
||||
*/
|
||||
private List<RpcApiDependency> dependencyList;
|
||||
|
||||
|
||||
public String getProjectName() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
public String getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public void setProjectId(String projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public List<RpcApiDoc> getApiDocList() {
|
||||
return apiDocList;
|
||||
}
|
||||
|
||||
public void setApiDocList(List<RpcApiDoc> apiDocList) {
|
||||
this.apiDocList = apiDocList;
|
||||
}
|
||||
|
||||
public List<ApiDocDict> getApiDocDictList() {
|
||||
return apiDocDictList;
|
||||
}
|
||||
|
||||
public void setApiDocDictList(List<ApiDocDict> apiDocDictList) {
|
||||
this.apiDocDictList = apiDocDictList;
|
||||
}
|
||||
|
||||
public List<ApiErrorCode> getErrorCodeList() {
|
||||
return errorCodeList;
|
||||
}
|
||||
|
||||
public void setErrorCodeList(List<ApiErrorCode> errorCodeList) {
|
||||
this.errorCodeList = errorCodeList;
|
||||
}
|
||||
|
||||
public List<RevisionLog> getRevisionLogs() {
|
||||
return revisionLogs;
|
||||
}
|
||||
|
||||
public void setRevisionLogs(List<RevisionLog> revisionLogs) {
|
||||
this.revisionLogs = revisionLogs;
|
||||
}
|
||||
|
||||
public List<RpcApiDependency> getDependencyList() {
|
||||
return dependencyList;
|
||||
}
|
||||
|
||||
public void setDependencyList(List<RpcApiDependency> dependencyList) {
|
||||
this.dependencyList = dependencyList;
|
||||
}
|
||||
}
|
|
@ -42,7 +42,7 @@ import static com.power.doc.constants.DocGlobalConstants.NO_COMMENTS_FOUND;
|
|||
/**
|
||||
* @author yu 2019/12/21.
|
||||
*/
|
||||
public interface IDocBuildTemplate {
|
||||
public interface IDocBuildTemplate<T> {
|
||||
|
||||
default String createDocRenderHeaders(List<ApiReqHeader> headers, boolean isAdoc) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -133,9 +133,9 @@ public interface IDocBuildTemplate {
|
|||
return null;
|
||||
}
|
||||
|
||||
List<ApiDoc> getApiData(ProjectDocConfigBuilder projectBuilder);
|
||||
List<T> getApiData(ProjectDocConfigBuilder projectBuilder);
|
||||
|
||||
ApiDoc getSingleApiData(ProjectDocConfigBuilder projectBuilder, String apiClassName);
|
||||
T getSingleApiData(ProjectDocConfigBuilder projectBuilder, String apiClassName);
|
||||
|
||||
boolean ignoreReturnObject(String typeName);
|
||||
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
/*
|
||||
* smart-doc
|
||||
*
|
||||
* Copyright (C) 2018-2020 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.power.doc.template;
|
||||
|
||||
import com.power.common.util.StringUtil;
|
||||
|
@ -6,7 +28,10 @@ import com.power.doc.constants.DocGlobalConstants;
|
|||
import com.power.doc.constants.DocTags;
|
||||
import com.power.doc.constants.DubboAnnotationConstants;
|
||||
import com.power.doc.helper.ParamsBuildHelper;
|
||||
import com.power.doc.model.*;
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.ApiParam;
|
||||
import com.power.doc.model.CustomRespField;
|
||||
import com.power.doc.model.JavaMethodDoc;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.utils.DocClassUtil;
|
||||
import com.power.doc.utils.DocUtil;
|
||||
|
@ -19,13 +44,12 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.power.doc.constants.DocGlobalConstants.NO_COMMENTS_FOUND;
|
||||
import static com.power.doc.constants.DocTags.IGNORE;
|
||||
|
||||
/**
|
||||
* @author yu 2020/1/29.
|
||||
*/
|
||||
public class JavaDocBuildTemplate {
|
||||
public class RpcDocBuildTemplate implements IDocBuildTemplate<RpcApiDoc> {
|
||||
|
||||
public List<RpcApiDoc> getApiData(ProjectDocConfigBuilder projectBuilder) {
|
||||
ApiConfig apiConfig = projectBuilder.getApiConfig();
|
||||
|
@ -50,7 +74,7 @@ public class JavaDocBuildTemplate {
|
|||
return apiDocList;
|
||||
}
|
||||
|
||||
public ApiDoc getSingleApiData(ProjectDocConfigBuilder projectBuilder, String apiClassName) {
|
||||
public RpcApiDoc getSingleApiData(ProjectDocConfigBuilder projectBuilder, String apiClassName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -227,60 +251,6 @@ public class JavaDocBuildTemplate {
|
|||
apiDoc.setAuthor(String.join(",",authorList));
|
||||
}
|
||||
|
||||
private List<ApiParam> buildReturnApiParams(JavaMethod method, ProjectDocConfigBuilder projectBuilder) {
|
||||
if (method.getReturns().isVoid()) {
|
||||
return null;
|
||||
}
|
||||
ApiReturn apiReturn = DocClassUtil.processReturnType(method.getReturnType().getGenericCanonicalName());
|
||||
String returnType = apiReturn.getGenericCanonicalName();
|
||||
String typeName = apiReturn.getSimpleName();
|
||||
if (this.ignoreReturnObject(typeName)) {
|
||||
return null;
|
||||
}
|
||||
if (JavaClassValidateUtil.isPrimitive(typeName)) {
|
||||
return ParamsBuildHelper.primitiveReturnRespComment(DocClassUtil.processTypeNameForParams(typeName));
|
||||
}
|
||||
if (JavaClassValidateUtil.isCollection(typeName)) {
|
||||
if (returnType.contains("<")) {
|
||||
String gicName = returnType.substring(returnType.indexOf("<") + 1, returnType.lastIndexOf(">"));
|
||||
if (JavaClassValidateUtil.isPrimitive(gicName)) {
|
||||
return ParamsBuildHelper.primitiveReturnRespComment("array of " + DocClassUtil.processTypeNameForParams(gicName));
|
||||
}
|
||||
return ParamsBuildHelper.buildParams(gicName, "", 0, null, projectBuilder.getCustomRespFieldMap(),
|
||||
Boolean.TRUE, new HashMap<>(), projectBuilder, null);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (JavaClassValidateUtil.isMap(typeName)) {
|
||||
String[] keyValue = DocClassUtil.getMapKeyValueType(returnType);
|
||||
if (keyValue.length == 0) {
|
||||
return null;
|
||||
}
|
||||
if (JavaClassValidateUtil.isPrimitive(keyValue[1])) {
|
||||
return ParamsBuildHelper.primitiveReturnRespComment("key value");
|
||||
}
|
||||
return ParamsBuildHelper.buildParams(keyValue[1], "", 0, null, projectBuilder.getCustomRespFieldMap(),
|
||||
Boolean.TRUE, new HashMap<>(), projectBuilder, null);
|
||||
}
|
||||
if (StringUtil.isNotEmpty(returnType)) {
|
||||
return ParamsBuildHelper.buildParams(returnType, "", 0, null, projectBuilder.getCustomRespFieldMap(),
|
||||
Boolean.TRUE, new HashMap<>(), projectBuilder, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String paramCommentResolve(String comment) {
|
||||
if (StringUtil.isEmpty(comment)) {
|
||||
comment = NO_COMMENTS_FOUND;
|
||||
} else {
|
||||
if (comment.contains("|")) {
|
||||
comment = comment.substring(0, comment.indexOf("|"));
|
||||
}
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
|
||||
private String methodDefinition(JavaMethod method) {
|
||||
StringBuilder methodBuilder = new StringBuilder();
|
||||
String returnClass = method.getReturnType().getGenericCanonicalName();
|
|
@ -54,7 +54,7 @@ import static com.power.doc.constants.DocTags.IGNORE;
|
|||
/**
|
||||
* @author yu 2019/12/21.
|
||||
*/
|
||||
public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
|
||||
public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
||||
|
||||
private List<ApiReqHeader> headers;
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
# Add dependency
|
||||
|
||||
```
|
||||
<%
|
||||
for(dependency in dependencyList){
|
||||
%>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.qdox</groupId>
|
||||
<artifactId>qdox</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<groupId>${dependency.groupId}</groupId>
|
||||
<artifactId>${dependency.artifactId}</artifactId>
|
||||
<version>${dependency.version}</version>
|
||||
</dependency>
|
||||
|
||||
<%}%>
|
||||
```
|
Loading…
Reference in New Issue