com.ly.doc.utils.ParamUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smart-doc Show documentation
Show all versions of smart-doc Show documentation
Smart-doc is a tool that supports both JAVA RESTFUL API and Apache Dubbo RPC interface document
generation.
package com.ly.doc.utils;
import java.util.*;
import com.ly.doc.builder.ProjectDocConfigBuilder;
import com.ly.doc.constants.DocGlobalConstants;
import com.ly.doc.constants.DocTags;
import com.ly.doc.model.ApiParam;
import com.power.common.util.CollectionUtil;
import com.power.common.util.StringUtil;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
/**
* @author chenqi
* @version 1.0
*/
public class ParamUtil {
public static JavaClass handleSeeEnum(ApiParam param, JavaField javaField, ProjectDocConfigBuilder builder, boolean jsonRequest,
Map tagsMap) {
JavaClass seeEnum = JavaClassUtil.getSeeEnum(javaField, builder);
if (Objects.isNull(seeEnum)) {
return null;
}
param.setType(DocGlobalConstants.ENUM);
Object value = JavaClassUtil.getEnumValue(seeEnum, !jsonRequest);
param.setValue(String.valueOf(value));
param.setEnumValues(JavaClassUtil.getEnumValues(seeEnum));
param.setEnumInfo(JavaClassUtil.getEnumInfo(seeEnum, builder));
// Override old value
if (tagsMap.containsKey(DocTags.MOCK) && StringUtil.isNotEmpty(tagsMap.get(DocTags.MOCK))) {
param.setValue(tagsMap.get(DocTags.MOCK));
}
return seeEnum;
}
public static String formatMockValue(String mock) {
if (StringUtil.isEmpty(mock)) {
return mock;
}
return mock.replaceAll("\\\\","");
}
public static List extractQualifiedName(List paramList) {
if (CollectionUtil.isEmpty(paramList)) {
return Collections.emptyList();
}
Set set = new HashSet<>();
for (ApiParam param : paramList) {
String className = param.getClassName();
if (StringUtil.isEmpty(className)) {
continue;
}
int index = className.indexOf("<");
if (index > -1) {
className = className.substring(0, index);
}
set.add(className);
}
return new ArrayList<>(set);
}
}