Supports replacing specified objects with custom objects to complete document rendering

This commit is contained in:
oppofind 2020-04-18 20:28:30 +08:00
parent 2821851ed2
commit 884763ec16
13 changed files with 598 additions and 322 deletions

View File

@ -1,7 +1,7 @@
## smart-doc版本
版本小于1.0都属于试用正式1.0起始发布将会等到文中提到的问题解决后才发布。
#### 版本号1.8.5
- 更新日期: 2020-04-xx
- 更新日期: 2020-04-19
- 更新内容:
1. maven插件错误码列表导出bug[git #I1EHXA](https://gitee.com/sunyurepository/smart-doc/issues/I1EHXA)。
2. 增加@PatchMapping支持[gitee #I1EDRF](https://gitee.com/sunyurepository/smart-doc/issues/I1EDRF)
@ -9,6 +9,7 @@
4. 修改当请求参数为泛型时数据解析错误问题。
5. 修复分组验证空指针问题,不对返回对象做分组验证处理。
6. 优化smart-doc-maven-plugin对多级maven项目的加载。
7. 支持请求参数对象替换成另外的对象来渲染文档
#### 版本号1.8.4
- 更新日期: 2020-03-30
- 更新内容:

View File

@ -26,10 +26,7 @@ import com.power.common.constants.Charset;
import com.power.common.util.CollectionUtil;
import com.power.common.util.StringUtil;
import com.power.doc.constants.DocGlobalConstants;
import com.power.doc.model.ApiConfig;
import com.power.doc.model.CustomRespField;
import com.power.doc.model.DocJavaField;
import com.power.doc.model.SourceCodePath;
import com.power.doc.model.*;
import com.power.doc.utils.JavaClassUtil;
import com.thoughtworks.qdox.JavaProjectBuilder;
import com.thoughtworks.qdox.model.JavaClass;
@ -54,6 +51,8 @@ public class ProjectDocConfigBuilder {
private Map<String, CustomRespField> customRespFieldMap = new ConcurrentHashMap<>();
private Map<String,String> replaceClassMap = new ConcurrentHashMap<>();
private String serverUrl;
private ApiConfig apiConfig;
@ -78,6 +77,7 @@ public class ProjectDocConfigBuilder {
this.loadJavaSource(apiConfig.getSourceCodePaths(), this.javaProjectBuilder);
this.initClassFilesMap();
this.initCustomResponseFieldsMap(apiConfig);
this.initReplaceClassMap(apiConfig);
}
private void loadJavaSource(List<SourceCodePath> paths, JavaProjectBuilder builder) {
@ -112,6 +112,14 @@ public class ProjectDocConfigBuilder {
}
}
private void initReplaceClassMap(ApiConfig config){
if (CollectionUtil.isNotEmpty(config.getApiObjectReplacements())) {
for (ApiObjectReplacement replace : config.getApiObjectReplacements()) {
replaceClassMap.put(replace.getClassName(),replace.getReplacementClassName());
}
}
}
public JavaClass getClassByName(String simpleName) {
JavaClass cls = javaProjectBuilder.getClassByName(simpleName);
@ -149,4 +157,9 @@ public class ProjectDocConfigBuilder {
public ApiConfig getApiConfig() {
return apiConfig;
}
public Map<String, String> getReplaceClassMap() {
return replaceClassMap;
}
}

View File

@ -1,3 +1,25 @@
/*
* smart-doc https://github.com/shalousun/smart-doc
*
* Copyright (C) 2019-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.filter;
import com.power.doc.constants.DocGlobalConstants;

View File

@ -1,3 +1,25 @@
/*
* smart-doc https://github.com/shalousun/smart-doc
*
* Copyright (C) 2019-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.filter;
import com.power.doc.model.ApiReturn;

View File

@ -1,3 +1,25 @@
/*
* smart-doc https://github.com/shalousun/smart-doc
*
* Copyright (C) 2019-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.filter;
import com.power.doc.model.ApiReturn;
@ -11,7 +33,7 @@ public interface ReturnTypeFilter {
/**
* filter return Type
* @param fullyName full type name
* @return
* @return ApiReturn
*/
ApiReturn doFilter(String fullyName);
}

View File

@ -1,3 +1,25 @@
/*
* smart-doc https://github.com/shalousun/smart-doc
*
* Copyright (C) 2019-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.filter;
import com.power.doc.model.ApiReturn;

View File

@ -1,3 +1,25 @@
/*
* smart-doc https://github.com/shalousun/smart-doc
*
* Copyright (C) 2019-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.filter;
import com.power.doc.constants.DocGlobalConstants;

View File

@ -1,301 +1,314 @@
/*
* smart-doc
*
* Copyright (C) 2019-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;
import com.power.common.util.CollectionUtil;
import com.power.doc.constants.DocLanguage;
import java.util.List;
import java.util.stream.Collectors;
/**
* Description:
* api config info
*
* @author yu 2018/06/18.
*/
public class ApiConfig {
/**
* Web server base url
*/
private String serverUrl;
/**
* Set comments check mode
*/
private boolean isStrict;
/**
* Merge all api doc into one document
*/
private boolean allInOne;
/**
* output path
*/
private String outPath;
/**
* source path
*/
private List<SourceCodePath> sourceCodePaths;
/**
* list of Request headers
*/
private List<ApiReqHeader> requestHeaders;
/**
* @since 1.7.5
* cover old all in one markdown
*/
private boolean coverOld;
/**
* list of custom response filed
*/
private List<CustomRespField> customResponseFields;
/**
* List of error code
*
* @return
*/
private List<ApiErrorCode> errorCodes;
/**
* controller package filters
*/
private String packageFilters;
/**
* List of change log
*/
private List<RevisionLog> revisionLogs;
/**
* @since 1.7+
*/
private boolean md5EncryptedHtmlName;
/**
* language support
*
* @since 1.7+
*/
private DocLanguage language;
/**
* adoc flag
*/
private boolean adoc;
/**
* api data dictionary
*/
private List<ApiDataDictionary> dataDictionaries;
/**
* @since 1.7.9
* api error code dictionary
*/
private List<ApiErrorCodeDictionary> errorCodeDictionaries;
/**
* @since 1.7.5
* project name
*/
private String projectName;
/**
* Skip Transient Field
*/
private boolean skipTransientField = true;
/**
* @since 1.7.10
* default show author
*/
private boolean showAuthor = true;
public String getServerUrl() {
return serverUrl;
}
public void setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
}
public boolean isStrict() {
return isStrict;
}
public void setStrict(boolean strict) {
isStrict = strict;
}
public String getOutPath() {
return outPath;
}
public void setOutPath(String outPath) {
this.outPath = outPath;
}
public List<ApiReqHeader> getRequestHeaders() {
return requestHeaders;
}
public void setRequestHeaders(ApiReqHeader... requestHeaders) {
this.requestHeaders = CollectionUtil.asList(requestHeaders);
this.requestHeaders.stream().map(header -> header.setDesc(header.getDesc() + "(Global)"))
.collect(Collectors.toList());
}
public List<CustomRespField> getCustomResponseFields() {
return customResponseFields;
}
public void setCustomResponseFields(CustomRespField... customResponseFields) {
this.customResponseFields = CollectionUtil.asList(customResponseFields);
}
public List<ApiErrorCode> getErrorCodes() {
return errorCodes;
}
public void setErrorCodes(List<ApiErrorCode> errorCodes) {
this.errorCodes = errorCodes;
}
public List<SourceCodePath> getSourceCodePaths() {
return sourceCodePaths;
}
public void setSourceCodePaths(SourceCodePath... sourcePaths) {
this.sourceCodePaths = CollectionUtil.asList(sourcePaths);
}
public boolean isAllInOne() {
return allInOne;
}
public void setAllInOne(boolean allInOne) {
this.allInOne = allInOne;
}
public String getPackageFilters() {
return packageFilters;
}
public void setPackageFilters(String packageFilters) {
this.packageFilters = packageFilters;
}
public List<RevisionLog> getRevisionLogs() {
return revisionLogs;
}
public void setRevisionLogs(RevisionLog... revisionLogs) {
this.revisionLogs = CollectionUtil.asList(revisionLogs);
}
public boolean isMd5EncryptedHtmlName() {
return md5EncryptedHtmlName;
}
public void setMd5EncryptedHtmlName(boolean md5EncryptedHtmlName) {
this.md5EncryptedHtmlName = md5EncryptedHtmlName;
}
public DocLanguage getLanguage() {
return language;
}
public void setLanguage(DocLanguage language) {
this.language = language;
}
public boolean isAdoc() {
return adoc;
}
public void setAdoc(boolean adoc) {
this.adoc = adoc;
}
public List<ApiDataDictionary> getDataDictionaries() {
return dataDictionaries;
}
public void setDataDictionaries(ApiDataDictionary... dataDictConfigs) {
this.dataDictionaries = CollectionUtil.asList(dataDictConfigs);
}
public List<ApiErrorCodeDictionary> getErrorCodeDictionaries() {
return errorCodeDictionaries;
}
public void setErrorCodeDictionaries(ApiErrorCodeDictionary... errorCodeDictConfigs) {
this.errorCodeDictionaries = CollectionUtil.asList(errorCodeDictConfigs);
}
public boolean isCoverOld() {
return coverOld;
}
public void setCoverOld(boolean coverOld) {
this.coverOld = coverOld;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public boolean isSkipTransientField() {
return skipTransientField;
}
public void setSkipTransientField(boolean skipTransientField) {
this.skipTransientField = skipTransientField;
}
public boolean isShowAuthor() {
return showAuthor;
}
public void setShowAuthor(boolean showAuthor) {
this.showAuthor = showAuthor;
}
}
/*
* smart-doc
*
* Copyright (C) 2019-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;
import com.power.common.util.CollectionUtil;
import com.power.doc.constants.DocLanguage;
import java.util.List;
import java.util.stream.Collectors;
/**
* Description:
* api config info
*
* @author yu 2018/06/18.
*/
public class ApiConfig {
/**
* Web server base url
*/
private String serverUrl;
/**
* Set comments check mode
*/
private boolean isStrict;
/**
* Merge all api doc into one document
*/
private boolean allInOne;
/**
* output path
*/
private String outPath;
/**
* source path
*/
private List<SourceCodePath> sourceCodePaths;
/**
* list of Request headers
*/
private List<ApiReqHeader> requestHeaders;
/**
* @since 1.7.5
* cover old all in one markdown
*/
private boolean coverOld;
/**
* list of custom response filed
*/
private List<CustomRespField> customResponseFields;
/**
* List of error code
*
* @return
*/
private List<ApiErrorCode> errorCodes;
/**
* controller package filters
*/
private String packageFilters;
/**
* List of change log
*/
private List<RevisionLog> revisionLogs;
/**
* @since 1.7+
*/
private boolean md5EncryptedHtmlName;
/**
* language support
*
* @since 1.7+
*/
private DocLanguage language;
/**
* adoc flag
*/
private boolean adoc;
/**
* api data dictionary
*/
private List<ApiDataDictionary> dataDictionaries;
/**
* @since 1.7.9
* api error code dictionary
*/
private List<ApiErrorCodeDictionary> errorCodeDictionaries;
/**
* list of custom response filed
*/
private List<ApiObjectReplacement> apiObjectReplacements;
/**
* @since 1.7.5
* project name
*/
private String projectName;
/**
* Skip Transient Field
*/
private boolean skipTransientField = true;
/**
* @since 1.7.10
* default show author
*/
private boolean showAuthor = true;
public String getServerUrl() {
return serverUrl;
}
public void setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
}
public boolean isStrict() {
return isStrict;
}
public void setStrict(boolean strict) {
isStrict = strict;
}
public String getOutPath() {
return outPath;
}
public void setOutPath(String outPath) {
this.outPath = outPath;
}
public List<ApiReqHeader> getRequestHeaders() {
return requestHeaders;
}
public void setRequestHeaders(ApiReqHeader... requestHeaders) {
this.requestHeaders = CollectionUtil.asList(requestHeaders);
this.requestHeaders.stream().map(header -> header.setDesc(header.getDesc() + "(Global)"))
.collect(Collectors.toList());
}
public List<CustomRespField> getCustomResponseFields() {
return customResponseFields;
}
public void setCustomResponseFields(CustomRespField... customResponseFields) {
this.customResponseFields = CollectionUtil.asList(customResponseFields);
}
public List<ApiErrorCode> getErrorCodes() {
return errorCodes;
}
public void setErrorCodes(List<ApiErrorCode> errorCodes) {
this.errorCodes = errorCodes;
}
public List<SourceCodePath> getSourceCodePaths() {
return sourceCodePaths;
}
public void setSourceCodePaths(SourceCodePath... sourcePaths) {
this.sourceCodePaths = CollectionUtil.asList(sourcePaths);
}
public boolean isAllInOne() {
return allInOne;
}
public void setAllInOne(boolean allInOne) {
this.allInOne = allInOne;
}
public String getPackageFilters() {
return packageFilters;
}
public void setPackageFilters(String packageFilters) {
this.packageFilters = packageFilters;
}
public List<RevisionLog> getRevisionLogs() {
return revisionLogs;
}
public void setRevisionLogs(RevisionLog... revisionLogs) {
this.revisionLogs = CollectionUtil.asList(revisionLogs);
}
public boolean isMd5EncryptedHtmlName() {
return md5EncryptedHtmlName;
}
public void setMd5EncryptedHtmlName(boolean md5EncryptedHtmlName) {
this.md5EncryptedHtmlName = md5EncryptedHtmlName;
}
public DocLanguage getLanguage() {
return language;
}
public void setLanguage(DocLanguage language) {
this.language = language;
}
public boolean isAdoc() {
return adoc;
}
public void setAdoc(boolean adoc) {
this.adoc = adoc;
}
public List<ApiDataDictionary> getDataDictionaries() {
return dataDictionaries;
}
public void setDataDictionaries(ApiDataDictionary... dataDictConfigs) {
this.dataDictionaries = CollectionUtil.asList(dataDictConfigs);
}
public List<ApiErrorCodeDictionary> getErrorCodeDictionaries() {
return errorCodeDictionaries;
}
public void setErrorCodeDictionaries(ApiErrorCodeDictionary... errorCodeDictConfigs) {
this.errorCodeDictionaries = CollectionUtil.asList(errorCodeDictConfigs);
}
public List<ApiObjectReplacement> getApiObjectReplacements() {
return apiObjectReplacements;
}
public void setApiObjectReplacements(ApiObjectReplacement... apiObjectReplaces) {
this.apiObjectReplacements = CollectionUtil.asList(apiObjectReplaces);
}
public boolean isCoverOld() {
return coverOld;
}
public void setCoverOld(boolean coverOld) {
this.coverOld = coverOld;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public boolean isSkipTransientField() {
return skipTransientField;
}
public void setSkipTransientField(boolean skipTransientField) {
this.skipTransientField = skipTransientField;
}
public boolean isShowAuthor() {
return showAuthor;
}
public void setShowAuthor(boolean showAuthor) {
this.showAuthor = showAuthor;
}
}

View File

@ -0,0 +1,55 @@
/*
* smart-doc
*
* Copyright (C) 2019-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;
/**
* @author yu 2020/4/18.
*/
public class ApiObjectReplacement {
private String className;
private String replacementClassName;
public static ApiObjectReplacement builder(){
return new ApiObjectReplacement();
}
public String getClassName() {
return className;
}
public ApiObjectReplacement setClassName(String className) {
this.className = className;
return this;
}
public String getReplacementClassName() {
return replacementClassName;
}
public ApiObjectReplacement setReplacementClassName(String replacementClassName) {
this.replacementClassName = replacementClassName;
return this;
}
}

View File

@ -1,3 +1,25 @@
/*
* smart-doc
*
* Copyright (C) 2019-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;
import com.thoughtworks.qdox.model.JavaField;

View File

@ -66,7 +66,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
int order = 0;
Collection<JavaClass> classes = projectBuilder.getJavaProjectBuilder().getClasses();
for (JavaClass cls : classes) {
String ignoreTag = JavaClassUtil.getClassTagsValue(cls, DocTags.IGNORE,Boolean.FALSE);
String ignoreTag = JavaClassUtil.getClassTagsValue(cls, DocTags.IGNORE, Boolean.FALSE);
if (!checkController(cls) || StringUtil.isNotEmpty(ignoreTag)) {
continue;
}
@ -100,7 +100,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
private List<ApiMethodDoc> buildControllerMethod(final JavaClass cls, ApiConfig apiConfig, ProjectDocConfigBuilder projectBuilder) {
String clazName = cls.getCanonicalName();
String classAuthor = JavaClassUtil.getClassTagsValue(cls, DocTags.AUTHOR,Boolean.TRUE);
String classAuthor = JavaClassUtil.getClassTagsValue(cls, DocTags.AUTHOR, Boolean.TRUE);
List<JavaAnnotation> classAnnotations = cls.getAnnotations();
String baseUrl = "";
for (JavaAnnotation annotation : classAnnotations) {
@ -193,6 +193,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
if (parameterList.size() < 1) {
return ApiRequestExample.builder().setUrl(apiMethodDoc.getUrl());
}
Map<String, String> replacementMap = configBuilder.getReplaceClassMap();
Map<String, String> pathParamsMap = new LinkedHashMap<>();
Map<String, String> paramsComments = DocUtil.getParamsComments(method, DocTags.PARAM, null);
List<String> springMvcRequestAnnotations = SpringMvcRequestAnnotationsEnum.listSpringMvcRequestAnnotations();
@ -201,18 +202,30 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
out:
for (JavaParameter parameter : parameterList) {
JavaType javaType = parameter.getType();
String paramName = parameter.getName();
String typeName = javaType.getFullyQualifiedName();
String gicTypeName = javaType.getGenericCanonicalName();
String rewriteClassName = null;
String commentClass = paramsComments.get(paramName);
if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) {
String[] comments = commentClass.split("\\|");
rewriteClassName = comments[comments.length - 1];
} else {
rewriteClassName = replacementMap.get(typeName);
}
// rewrite class
if (DocUtil.isClassName(rewriteClassName)) {
gicTypeName = rewriteClassName;
typeName = DocClassUtil.getSimpleName(rewriteClassName);
}
if (JavaClassValidateUtil.isMvcIgnoreParams(typeName)) {
continue;
}
typeName = DocClassUtil.rewriteRequestParam(typeName);
String simpleTypeName = javaType.getValue().toLowerCase();
String gicTypeName = javaType.getGenericCanonicalName();
typeName = DocClassUtil.rewriteRequestParam(typeName);
gicTypeName = DocClassUtil.rewriteRequestParam(gicTypeName);
JavaClass javaClass = configBuilder.getJavaProjectBuilder().getClassByName(typeName);
String[] globGicName = DocClassUtil.getSimpleGicName(gicTypeName);
String paramName = parameter.getName();
String comment = this.paramCommentResolve(paramsComments.get(paramName));
String mockValue = "";
if (JavaClassValidateUtil.isPrimitive(typeName)) {
@ -375,6 +388,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
private List<ApiParam> requestParams(final JavaMethod javaMethod, final String tagName, ProjectDocConfigBuilder builder) {
boolean isStrict = builder.getApiConfig().isStrict();
Map<String, CustomRespField> responseFieldMap = new HashMap<>();
Map<String, String> replacementMap = builder.getReplaceClassMap();
String className = javaMethod.getDeclaringClass().getCanonicalName();
Map<String, String> paramTagMap = DocUtil.getParamsComments(javaMethod, tagName, className);
List<JavaParameter> parameterList = javaMethod.getParameters();
@ -389,11 +403,24 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
String typeName = parameter.getType().getGenericCanonicalName();
String simpleName = parameter.getType().getValue().toLowerCase();
String fullTypeName = parameter.getType().getFullyQualifiedName();
String rewriteClassName = null;
String commentClass = paramTagMap.get(paramName);
if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) {
String[] comments = commentClass.split("\\|");
rewriteClassName = comments[comments.length - 1];
} else {
rewriteClassName = replacementMap.get(fullTypeName);
}
// rewrite class
if (DocUtil.isClassName(rewriteClassName)) {
typeName = rewriteClassName;
fullTypeName = DocClassUtil.getSimpleName(rewriteClassName);
}
if (JavaClassValidateUtil.isMvcIgnoreParams(typeName)) {
continue out;
}
fullTypeName = DocClassUtil.rewriteRequestParam(fullTypeName);
typeName = DocClassUtil.rewriteRequestParam(fullTypeName);
fullTypeName = DocClassUtil.rewriteRequestParam(fullTypeName);
typeName = DocClassUtil.rewriteRequestParam(typeName);
if (!paramTagMap.containsKey(paramName) && JavaClassValidateUtil.isPrimitive(fullTypeName) && isStrict) {
throw new RuntimeException("ERROR: Unable to find javadoc @param for actual param \""
+ paramName + "\" in method " + javaMethod.getName() + " from " + className);

View File

@ -23,10 +23,7 @@
package com.power.doc.utils;
import com.github.javafaker.Faker;
import com.power.common.util.DateTimeUtil;
import com.power.common.util.IDCardUtil;
import com.power.common.util.RandomUtil;
import com.power.common.util.StringUtil;
import com.power.common.util.*;
import com.power.doc.constants.DocAnnotationConstants;
import com.power.doc.constants.DocGlobalConstants;
import com.power.doc.model.FormData;
@ -37,6 +34,8 @@ import com.thoughtworks.qdox.model.JavaMethod;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@ -51,6 +50,10 @@ public class DocUtil {
//private static Faker faker = new Faker(new Locale("smart-doc_language"));
private static Faker enFaker = new Faker(new Locale("en-US"));
private static String CLASS_PATTERN = "^([A-Za-z]{1}[A-Za-z\\d_]*\\.)+[A-Za-z][A-Za-z\\d_]*$";
public static final String CONTAINS_CHINESE_PATTERN = "[\u4E00-\u9FA5|\\|\\|\\。|\\|\\|\\《|\\》|\\“|\\”|\\|\\|\\|\\【|\\】]";
private static Map<String, String> fieldValue = new LinkedHashMap<>();
static {
@ -195,7 +198,18 @@ public class DocUtil {
* @return boolean
*/
public static boolean isClassName(String className) {
if (StringUtil.isEmpty(className)) {
if (StringUtil.isEmpty(className) || !className.contains(".")) {
return false;
}
if (isContainsChinese(className)) {
return false;
}
String classNameTemp = className;
if (className.contains("<")) {
int index = className.indexOf("<");
classNameTemp = className.substring(0, index);
}
if (!ValidateUtil.validate(classNameTemp, CLASS_PATTERN)) {
return false;
}
if (className.contains("<") && !className.contains(">")) {
@ -445,4 +459,22 @@ public class DocUtil {
return false;
}
}
/**
* contains chinese
*
* @param str str
* @return boolean
*/
public static boolean isContainsChinese(String str) {
if (StringUtil.isEmpty(str)) {
return true;
}
Pattern p = Pattern.compile(CONTAINS_CHINESE_PATTERN);
Matcher m = p.matcher(str);
if (m.find()) {
return true;
}
return false;
}
}

View File

@ -79,8 +79,11 @@ public class JavaClassUtil {
fieldList.add(docJavaField);
}
}
JavaClass pcls = cls1.getSuperJavaClass();
fieldList.addAll(getFields(pcls, i));
// ignore enum parent class
if (!cls1.isEnum()) {
JavaClass parentClass = cls1.getSuperJavaClass();
fieldList.addAll(getFields(parentClass, i));
}
List<DocJavaField> docJavaFields = new ArrayList<>();
for (JavaField javaField : cls1.getFields()) {
docJavaFields.add(DocJavaField.builder().setComment(javaField.getComment()).setJavaField(javaField));