修改buildReqJson方法
This commit is contained in:
parent
59007f8ac6
commit
7be5bbc8e8
File diff suppressed because it is too large
Load Diff
|
@ -31,5 +31,9 @@ public class DocAnnotationConstants {
|
|||
|
||||
public static final String DEFAULT_VALUE_PROP = "defaultValue";
|
||||
|
||||
public static final String SHORT_REQUSRT_BODY = "RequestBody";
|
||||
|
||||
public static final String SHORT_REQUSRT_HEADER = "RequestHeader";
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -102,4 +102,6 @@ public class DocGlobalConstants {
|
|||
public static final String POSTMAN_MODE_RAW ="raw";
|
||||
|
||||
public static final String HTTP_POST = "POST";
|
||||
|
||||
public static final String SHORT_MULTIPART_FILE_FULLY = "MultipartFile";
|
||||
}
|
||||
|
|
|
@ -1,18 +1,28 @@
|
|||
package com.power.doc.model.postman.request.body;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xingzi
|
||||
*/
|
||||
public class BodyBean {
|
||||
private String mode;
|
||||
private String raw;
|
||||
private FormData formdata;
|
||||
private List<FormData> formdata;
|
||||
private BodyOptions options;
|
||||
|
||||
public BodyBean(boolean isFile) {
|
||||
if(isFile){
|
||||
this.formdata = new FormData();
|
||||
public List<FormData> getFormdata() {
|
||||
return formdata;
|
||||
}
|
||||
|
||||
public void setFormdata(List<FormData> formdata) {
|
||||
this.formdata = formdata;
|
||||
}
|
||||
|
||||
public BodyBean(boolean isFormData) {
|
||||
if(isFormData){
|
||||
|
||||
}else {
|
||||
this.options = new BodyOptions();
|
||||
}
|
||||
|
@ -34,17 +44,6 @@ public class BodyBean {
|
|||
this.raw = raw;
|
||||
}
|
||||
|
||||
private class FormData{
|
||||
private String key;
|
||||
private String type;
|
||||
private String src;
|
||||
|
||||
FormData() {
|
||||
this.key = "file";
|
||||
this.type = "file";
|
||||
this.src = "";
|
||||
}
|
||||
}
|
||||
private class BodyOptions{
|
||||
private Raw raw;
|
||||
public BodyOptions() {
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.power.doc.model.postman.request.body;
|
||||
|
||||
/**
|
||||
* @author xingzi 2019/12/21 20:20
|
||||
*/
|
||||
public class FormData {
|
||||
private String key;
|
||||
private String type;
|
||||
private String src;
|
||||
private String value;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getSrc() {
|
||||
return src;
|
||||
}
|
||||
|
||||
public void setSrc(String src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -510,4 +510,13 @@ public class DocClassUtil {
|
|||
}
|
||||
return className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is FormData File
|
||||
* @param typeName 参数全称
|
||||
* @return
|
||||
*/
|
||||
public static boolean isFormDataFile(String typeName){
|
||||
return typeName.contains(DocGlobalConstants.SHORT_MULTIPART_FILE_FULLY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package com.power.doc.utils;
|
||||
|
||||
import com.power.common.util.StringUtil;
|
||||
import com.power.common.util.UrlUtil;
|
||||
|
||||
import com.power.doc.builder.SourceBuilder;
|
||||
import com.power.doc.builder.SourceBuilders;
|
||||
import com.power.doc.constants.DocAnnotationConstants;
|
||||
import com.power.doc.constants.DocGlobalConstants;
|
||||
import com.power.doc.model.CustomRespField;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
import com.thoughtworks.qdox.model.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xingzi 2019/12/21 18:30
|
||||
*/
|
||||
public class ReqJsonUtil {
|
||||
|
||||
public static String buildUrl(String uri, boolean containsBrace, Map<String, String> paramsMap) {
|
||||
String url;
|
||||
String[] urls = uri.split(";");
|
||||
if (containsBrace) {
|
||||
url = DocUtil.formatAndRemove(urls[0], paramsMap);
|
||||
url = UrlUtil.urlJoin(url, paramsMap);
|
||||
} else {
|
||||
url = UrlUtil.urlJoin(urls[0], paramsMap);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public static Map<String, String> buildGetParam(List<JavaParameter> parameter) {
|
||||
Map<String, String> paramsMap = new HashMap<>(6);
|
||||
param:
|
||||
for (JavaParameter javaParameter : parameter) {
|
||||
JavaType javaType = javaParameter.getType();
|
||||
String simpleTypeName = javaType.getValue();
|
||||
String typeName = javaType.getFullyQualifiedName();
|
||||
String paraName = javaParameter.getName();
|
||||
JavaClass javaClass = new JavaProjectBuilder().getClassByName(typeName);
|
||||
//如果参数是header 继续下一个参数
|
||||
for (JavaAnnotation annotation : javaParameter.getAnnotations()) {
|
||||
if (annotation.getType().getSimpleName().equals(DocAnnotationConstants.SHORT_REQUSRT_HEADER)) {
|
||||
continue param;
|
||||
}
|
||||
}
|
||||
//如果是基本数据类型
|
||||
if (DocClassUtil.isPrimitive(typeName)) {
|
||||
paramsMap.put(paraName, DocUtil.getValByTypeAndFieldName(simpleTypeName, paraName,
|
||||
true));
|
||||
}
|
||||
//是枚举
|
||||
else if (javaClass.isEnum()) {
|
||||
Object value = handleEnumValue(javaClass, Boolean.TRUE);
|
||||
paramsMap.put(paraName, StringUtil.removeQuotes(String.valueOf(value)));
|
||||
}
|
||||
//如果是基本数据类型数组
|
||||
else if (DocClassUtil.isPrimitiveArray(typeName)) {
|
||||
paramsMap.put(paraName, DocUtil.getValByTypeAndFieldName(simpleTypeName, paraName,
|
||||
true));
|
||||
}
|
||||
//不是基本数据类型
|
||||
else {
|
||||
paramsMap.put(paraName, "can't create data for this type");
|
||||
}
|
||||
|
||||
}
|
||||
return paramsMap;
|
||||
}
|
||||
public static String createFormData(){
|
||||
|
||||
return "sd";
|
||||
}
|
||||
private static Object handleEnumValue(JavaClass javaClass, boolean returnEnum) {
|
||||
List<JavaField> javaFields = javaClass.getEnumConstants();
|
||||
Object value = null;
|
||||
int index = 0;
|
||||
for (JavaField javaField : javaFields) {
|
||||
String simpleName = javaField.getType().getSimpleName();
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
valueBuilder.append("\"").append(javaField.getName()).append("\"").toString();
|
||||
if (returnEnum) {
|
||||
value = valueBuilder.toString();
|
||||
return value;
|
||||
}
|
||||
if (!DocClassUtil.isPrimitive(simpleName) && index < 1) {
|
||||
if (null != javaField.getEnumConstantArguments()) {
|
||||
value = javaField.getEnumConstantArguments().get(0);
|
||||
} else {
|
||||
value = valueBuilder.toString();
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue