support group tag
This commit is contained in:
parent
9c404e5f81
commit
986a213553
|
@ -156,7 +156,11 @@ public class OpenApiBuilder {
|
|||
Map<String, Object> request = new HashMap<>(20);
|
||||
request.put("summary", apiMethodDoc.getDesc());
|
||||
request.put("description", apiMethodDoc.getDetail());
|
||||
request.put("tags", new String[]{apiDoc.getDesc()});
|
||||
if (StringUtil.isNotEmpty(apiMethodDoc.getGroup())) {
|
||||
request.put("tags", new String[]{apiMethodDoc.getGroup()});
|
||||
} else {
|
||||
request.put("tags", new String[]{apiDoc.getDesc()});
|
||||
}
|
||||
request.put("requestBody", buildRequestBody(apiMethodDoc));
|
||||
request.put("parameters", buildParameters(apiMethodDoc));
|
||||
request.put("responses", buildResponses(apiMethodDoc));
|
||||
|
|
|
@ -31,7 +31,7 @@ public interface DocTags {
|
|||
String AUTHOR = "author";
|
||||
|
||||
/**
|
||||
* java verion tag
|
||||
* java version tag
|
||||
*/
|
||||
String VERSION = "version";
|
||||
|
||||
|
@ -60,6 +60,11 @@ public interface DocTags {
|
|||
*/
|
||||
String ORDER = "order";
|
||||
|
||||
/**
|
||||
* custom @group tag
|
||||
*/
|
||||
String GROUP = "group";
|
||||
|
||||
/**
|
||||
* Ignore ResponseBodyAdvice
|
||||
*/
|
||||
|
|
|
@ -160,6 +160,10 @@ public class ApiMethodDoc implements Serializable {
|
|||
*/
|
||||
private Map<String,Object> requestSchema;
|
||||
|
||||
/**
|
||||
* api group
|
||||
*/
|
||||
private String group;
|
||||
|
||||
public String getMethodId() {
|
||||
return methodId;
|
||||
|
@ -346,6 +350,14 @@ public class ApiMethodDoc implements Serializable {
|
|||
this.requestSchema = requestSchema;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
|
|
|
@ -115,6 +115,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
ProjectDocConfigBuilder projectBuilder) {
|
||||
String clazName = cls.getCanonicalName();
|
||||
boolean paramsDataToTree = projectBuilder.getApiConfig().isParamsDataToTree();
|
||||
String group = JavaClassUtil.getClassTagsValue(cls, DocTags.GROUP, Boolean.TRUE);
|
||||
String classAuthor = JavaClassUtil.getClassTagsValue(cls, DocTags.AUTHOR, Boolean.TRUE);
|
||||
List<JavaAnnotation> classAnnotations = cls.getAnnotations();
|
||||
Map<String, String> constantsMap = projectBuilder.getConstantsMap();
|
||||
|
@ -158,9 +159,14 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
if (StringUtil.isEmpty(method.getComment()) && apiConfig.isStrict()) {
|
||||
throw new RuntimeException("Unable to find comment for method " + method.getName() + " in " + cls.getCanonicalName());
|
||||
}
|
||||
|
||||
methodOrder++;
|
||||
ApiMethodDoc apiMethodDoc = new ApiMethodDoc();
|
||||
DocletTag docletTag = method.getTagByName(DocTags.GROUP);
|
||||
if (Objects.nonNull(docletTag)) {
|
||||
apiMethodDoc.setGroup(docletTag.getValue());
|
||||
} else {
|
||||
apiMethodDoc.setGroup(group);
|
||||
}
|
||||
methodOrder++;
|
||||
apiMethodDoc.setName(method.getName());
|
||||
apiMethodDoc.setOrder(methodOrder);
|
||||
String comment = DocUtil.getEscapeAndCleanComment(method.getComment());
|
||||
|
@ -509,8 +515,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
ApiParam param = ApiParam.of().setField(paramName).setType("file")
|
||||
.setId(paramList.size() + 1).setQueryParam(true)
|
||||
.setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
|
||||
if(typeName.contains("[]")){
|
||||
comment = comment+"(array of file)";
|
||||
if (typeName.contains("[]")) {
|
||||
comment = comment + "(array of file)";
|
||||
param.setDesc(comment);
|
||||
param.setHasItems(true);
|
||||
}
|
||||
|
@ -608,7 +614,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
}
|
||||
} else if (JavaClassValidateUtil.isMap(fullTypeName)) {
|
||||
log.warning("When using smart-doc, it is not recommended to use Map to receive parameters, Check it in "
|
||||
+ javaMethod.getDeclaringClass().getCanonicalName()+"#"+javaMethod.getName());
|
||||
+ javaMethod.getDeclaringClass().getCanonicalName() + "#" + javaMethod.getName());
|
||||
|
||||
if (DocGlobalConstants.JAVA_MAP_FULLY.equals(typeName)) {
|
||||
ApiParam apiParam = ApiParam.of().setField(paramName).setType("map")
|
||||
|
@ -624,7 +630,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
continue;
|
||||
}
|
||||
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
|
||||
if(JavaClassValidateUtil.isPrimitive(gicNameArr[1])){
|
||||
if (JavaClassValidateUtil.isPrimitive(gicNameArr[1])) {
|
||||
ApiParam apiParam = ApiParam.of().setField(paramName).setType("map")
|
||||
.setId(paramList.size() + 1)
|
||||
.setPathParam(isPathVariable)
|
||||
|
|
|
@ -369,7 +369,7 @@ public class JavaClassUtil {
|
|||
}
|
||||
return result.toString();
|
||||
}
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue