增强customRepfiled#97 修改当有controllerAdvice时返回问题#96
This commit is contained in:
parent
8333309bc6
commit
c97950cbb2
|
@ -51,7 +51,7 @@ public class JsonBuildHelper {
|
|||
*/
|
||||
public static String buildReturnJson(DocJavaMethod docJavaMethod, ProjectDocConfigBuilder builder) {
|
||||
JavaMethod method = docJavaMethod.getJavaMethod();
|
||||
if (method.getReturns().isVoid()) {
|
||||
if (method.getReturns().isVoid() && Objects.isNull(builder.getApiConfig().getResponseBodyAdvice())) {
|
||||
return "Doesn't return a value.";
|
||||
}
|
||||
String returnTypeGenericCanonicalName = method.getReturnType().getGenericCanonicalName();
|
||||
|
@ -228,8 +228,11 @@ public class JsonBuildHelper {
|
|||
}
|
||||
}
|
||||
String typeSimpleName = field.getType().getSimpleName();
|
||||
|
||||
String fieldGicName = docField.getGenericCanonicalName();
|
||||
CustomRespField customResponseField = builder.getCustomRespFieldMap().get(fieldName);
|
||||
if(customResponseField !=null && typeSimpleName.equals(customResponseField.getOwnerClassName()) && (customResponseField.isIgnore()) && isResp){
|
||||
continue;
|
||||
}
|
||||
data0.append("\"").append(fieldName).append("\":");
|
||||
String fieldValue = "";
|
||||
if (tagsMap.containsKey(DocTags.MOCK) && StringUtil.isNotEmpty(tagsMap.get(DocTags.MOCK))) {
|
||||
|
@ -245,7 +248,6 @@ public class JsonBuildHelper {
|
|||
if (StringUtil.isEmpty(fieldValue)) {
|
||||
fieldValue = DocUtil.getValByTypeAndFieldName(typeSimpleName, field.getName());
|
||||
}
|
||||
CustomRespField customResponseField = builder.getCustomRespFieldMap().get(fieldName);
|
||||
if (null != customResponseField ) {
|
||||
Object val = customResponseField.getValue();
|
||||
if (null != val) {
|
||||
|
|
|
@ -148,6 +148,10 @@ public class ParamsBuildHelper {
|
|||
boolean strRequired = false;
|
||||
int annotationCounter = 0;
|
||||
|
||||
CustomRespField customResponseField = responseFieldMap.get(fieldName);
|
||||
if(customResponseField !=null && simpleName.equals(customResponseField.getOwnerClassName()) && (customResponseField.isIgnore()) && isResp){
|
||||
continue;
|
||||
}
|
||||
an:
|
||||
for (JavaAnnotation annotation : javaAnnotations) {
|
||||
String simpleAnnotationName = annotation.getType().getValue();
|
||||
|
@ -201,7 +205,7 @@ public class ParamsBuildHelper {
|
|||
}
|
||||
}
|
||||
//cover comment
|
||||
CustomRespField customResponseField = responseFieldMap.get(field.getName());
|
||||
|
||||
String comment;
|
||||
if (null != customResponseField && StringUtil.isNotEmpty(customResponseField.getDesc())
|
||||
&& simpleName.equals(customResponseField.getOwnerClassName())) {
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
package com.power.doc.model;
|
||||
|
||||
/**
|
||||
* @author xingzi
|
||||
* @date 2021/4/3 15:37
|
||||
**/
|
||||
public class CustomReqField {
|
||||
/**
|
||||
* field name
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* field description
|
||||
*/
|
||||
private String desc;
|
||||
|
||||
/**
|
||||
* owner class
|
||||
*/
|
||||
private String ownerClassName;
|
||||
|
||||
/**
|
||||
* default value
|
||||
*/
|
||||
private Object value;
|
||||
/**
|
||||
* required
|
||||
*/
|
||||
private boolean require;
|
||||
|
||||
/**
|
||||
* ignored
|
||||
*/
|
||||
private boolean ignore;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CustomReqField setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public CustomReqField setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getOwnerClassName() {
|
||||
return ownerClassName;
|
||||
}
|
||||
|
||||
public CustomReqField setOwnerClassName(String ownerClassName) {
|
||||
this.ownerClassName = ownerClassName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public CustomReqField setValue(Object value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isRequire() {
|
||||
return require;
|
||||
}
|
||||
|
||||
public CustomReqField setRequire(boolean require) {
|
||||
this.require = require;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isIgnore() {
|
||||
return ignore;
|
||||
}
|
||||
|
||||
public CustomReqField setIgnore(boolean ignore) {
|
||||
this.ignore = ignore;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CustomReqField{" +
|
||||
"name='" + name + '\'' +
|
||||
", desc='" + desc + '\'' +
|
||||
", ownerClassName='" + ownerClassName + '\'' +
|
||||
", value=" + value +
|
||||
", require=" + require +
|
||||
", ignore=" + ignore +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -51,6 +51,9 @@ public class CustomRespField {
|
|||
*/
|
||||
private Object value;
|
||||
|
||||
|
||||
private boolean ignore;
|
||||
|
||||
public static CustomRespField builder() {
|
||||
return new CustomRespField();
|
||||
}
|
||||
|
@ -91,6 +94,15 @@ public class CustomRespField {
|
|||
return this;
|
||||
}
|
||||
|
||||
public boolean isIgnore() {
|
||||
return ignore;
|
||||
}
|
||||
|
||||
public CustomRespField setIgnore(boolean ignore) {
|
||||
this.ignore = ignore;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ApiDocTest {
|
|||
//不指定SourcePaths默认加载代码为项目src/main/java下的
|
||||
config.setSourceCodePaths(
|
||||
SourceCodePath.builder().setDesc("本项目代码")
|
||||
.setPath("C:\\Users\\17717\\Desktop\\api-doc-test")
|
||||
.setPath("C:\\Users\\xingzi\\Desktop\\api-doc-test")
|
||||
|
||||
//SourcePath.path().setPath("F:\\Personal\\project\\smart\\src\\main\\java")
|
||||
//SourcePath.path().setDesc("加载项目外代码").setPath("E:\\ApplicationPower\\ApplicationPower\\Common-util\\src\\main\\java")
|
||||
|
@ -66,7 +66,8 @@ public class ApiDocTest {
|
|||
// CustomRespField.field().setName("success").setDesc("成功返回true,失败返回false"),
|
||||
// CustomRespField.field().setName("message").setDesc("接口响应信息"),
|
||||
// CustomRespField.field().setName("data").setDesc("接口响应数据"),
|
||||
CustomRespField.builder().setName("code").setValue("00000")
|
||||
CustomRespField.builder().setName("msg").setDesc("消息测试").setIgnore(true).setValue("000200"),
|
||||
CustomRespField.builder().setName("code2").setDesc("code测试").setIgnore(false).setValue("010000")
|
||||
//.setDesc("响应代码")
|
||||
);
|
||||
config.setPackageFilters("com.power.doc.controller.UserController");
|
||||
|
@ -75,12 +76,17 @@ public class ApiDocTest {
|
|||
RevisionLog.builder().setRevisionTime("2018/12/15").setAuthor("chen").setRemarks("测试").setStatus("创建").setVersion("V1.0"),
|
||||
RevisionLog.builder().setRevisionTime("2018/12/16").setAuthor("chen2").setRemarks("测试2").setStatus("修改").setVersion("V2.0")
|
||||
);
|
||||
// config.setResponseBodyAdvice(ResponseBodyAdvice.builder()
|
||||
// .setDataField("data")
|
||||
// .setDataField("dadada")
|
||||
// .setClassName("com.power.common.model.CommonResult"));
|
||||
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
TornaBuilder.buildApiDoc(config);
|
||||
OpenApiBuilder.buildOpenApi(config);
|
||||
//TornaBuilder.buildApiDoc(config);
|
||||
//OpenApiBuilder.buildOpenApi(config);
|
||||
HtmlApiDocBuilder.buildApiDoc(config);
|
||||
long end = System.currentTimeMillis();
|
||||
DateTimeUtil.printRunTime(end, start);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue