This commit is contained in:
oppofind 2021-04-24 15:18:08 +08:00
parent 385ab90606
commit 4b13cbe83b
2 changed files with 49 additions and 4 deletions

View File

@ -1,5 +1,13 @@
## smart-doc版本
版本小于1.0都属于试用正式1.0起始发布将会等到文中提到的问题解决后才发布。
#### 版本号2.1.4
- 更新日期: 2020-04-24
- 更新内容:
1. 修复Controller继承时父类的Mapping未继承的问题。
2. 修复配置responseBodyAdvice后controller中void方法返回显示错误。
3. 修复往torna推送漏掉pathParams的问题。
4. 修复非json请求集合中绑定枚举强制检查错误的问题。
5. 新增requestAdvice支持可以实现请求参数包装
#### 版本号2.1.3
- 更新日期: 2020-04-11
- 更新内容:

View File

@ -120,7 +120,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
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();
List<JavaAnnotation> classAnnotations = this.getAnnotations(cls);
Map<String, String> constantsMap = projectBuilder.getConstantsMap();
String baseUrl = "";
for (JavaAnnotation annotation : classAnnotations) {
@ -411,7 +411,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
if (JavaClassValidateUtil.isArray(gicName)) {
gicName = gicName.substring(0, gicName.indexOf("["));
}
if (!JavaClassValidateUtil.isPrimitive(gicName)) {
if (!JavaClassValidateUtil.isPrimitive(gicName)
&&!configBuilder.getJavaProjectBuilder().getClassByName(gicName).isEnum()) {
throw new RuntimeException("Spring MVC can't support binding Collection on method "
+ method.getName() + "Check it in " + method.getDeclaringClass().getCanonicalName());
}
@ -667,14 +668,29 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
if (JavaClassValidateUtil.isArray(gicName)) {
gicName = gicName.substring(0, gicName.indexOf("["));
}
if (JavaClassValidateUtil.isPrimitive(gicName)) {
JavaClass gicJavaClass = builder.getJavaProjectBuilder().getClassByName(gicName);
if(gicJavaClass.isEnum()){
Object value = JavaClassUtil.getEnumValue(gicJavaClass, Boolean.TRUE);
ApiParam param = ApiParam.of().setField(paramName).setDesc(comment + ",[array of enum]")
.setRequired(required)
.setPathParam(isPathVariable)
.setQueryParam(queryParam)
.setId(paramList.size() + 1)
.setType("array").setValue(String.valueOf(value));
paramList.add(param);
if (requestBodyCounter > 0) {
Map<String, Object> map = OpenApiSchemaUtil.arrayTypeSchema(gicName);
docJavaMethod.setRequestSchema(map);
}
} else if (JavaClassValidateUtil.isPrimitive(gicName)) {
String shortSimple = DocClassUtil.processTypeNameForParams(gicName);
ApiParam param = ApiParam.of().setField(paramName).setDesc(comment + ",[array of " + shortSimple + "]")
.setRequired(required)
.setPathParam(isPathVariable)
.setQueryParam(queryParam)
.setId(paramList.size() + 1)
.setType("array");
.setType("array")
.setValue(DocUtil.getValByTypeAndFieldName(gicName,paramName));
paramList.add(param);
if (requestBodyCounter > 0) {
Map<String, Object> map = OpenApiSchemaUtil.arrayTypeSchema(gicName);
@ -878,4 +894,25 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
paramList.add(apiParam);
mappingParams.put(paramName, null);
}
private List<JavaAnnotation> getAnnotations(JavaClass cls) {
List<JavaAnnotation> annotationsList = cls.getAnnotations();
boolean flag = annotationsList.stream().anyMatch(item -> {
String annotationName = item.getType().getValue();
if (DocAnnotationConstants.REQUEST_MAPPING.equals(annotationName) ||
DocGlobalConstants.REQUEST_MAPPING_FULLY.equals(annotationName)) {
return true;
}
return false;
});
// child override parent set
if (flag) {
return annotationsList;
}
JavaClass superJavaClass = cls.getSuperJavaClass();
if (!"Object".equals(superJavaClass.getSimpleName())) {
annotationsList.addAll(getAnnotations(superJavaClass));
}
return annotationsList;
}
}