support gitee #I2M8UX .

This commit is contained in:
oppofind 2021-01-30 17:53:14 +08:00
parent 2c4c17bd8d
commit 8e9240f187
4 changed files with 115 additions and 24 deletions

View File

@ -7,6 +7,7 @@
2. 修复带正则的path路径参数解析出现截取越界的问题。
3. 添加对默认接口实现中get方法重写忽略的能力解析。
4. 修改数组、map等字段类型的自定义mock值显示错误问题。
5. 修复对mapping中headers的处理。
#### 版本号2.0.6
- 更新日期: 2020-01-15
- 更新内容:

View File

@ -57,31 +57,18 @@ public class SpringMVCRequestHeaderHandler {
if (!isMapping(annotationName) || Objects.isNull(headersObject)) {
continue;
}
String mappingHeader = StringUtil.removeQuotes(headersObject.toString());
if (!mappingHeader.startsWith("[")) {
processMappingHeaders(mappingHeader, mappingHeaders);
continue;
}
List<String> headers = (LinkedList) headersObject;
for (String str : headers) {
String header = StringUtil.removeQuotes(str);
if (header.startsWith("!")) {
continue;
}
if (header.contains("!=")) {
String headerName = header.substring(0, header.indexOf("!"));
ApiReqHeader apiReqHeader = ApiReqHeader.builder().setName(headerName)
.setRequired(true).setValue(null).setDesc(header).setType("string");
mappingHeaders.add(apiReqHeader);
} else {
String headerName;
String headerValue = null;
if (header.contains("=")) {
int index = header.indexOf("=");
headerName = header.substring(0, header.indexOf("="));
headerValue = header.substring(index + 1);
} else {
headerName = header;
}
ApiReqHeader apiReqHeader = ApiReqHeader.builder().setName(headerName)
.setRequired(true).setValue(headerValue).setDesc(header).setType("string");
mappingHeaders.add(apiReqHeader);
}
processMappingHeaders(header, mappingHeaders);
}
}
List<ApiReqHeader> reqHeaders = new ArrayList<>();
@ -142,4 +129,26 @@ public class SpringMVCRequestHeaderHandler {
return false;
}
}
public void processMappingHeaders(String header, List<ApiReqHeader> mappingHeaders) {
if (header.contains("!=")) {
String headerName = header.substring(0, header.indexOf("!"));
ApiReqHeader apiReqHeader = ApiReqHeader.builder().setName(headerName)
.setRequired(true).setValue(null).setDesc("header condition").setType("string");
mappingHeaders.add(apiReqHeader);
} else {
String headerName;
String headerValue = null;
if (header.contains("=")) {
int index = header.indexOf("=");
headerName = header.substring(0, index);
headerValue = header.substring(index + 1);
} else {
headerName = header;
}
ApiReqHeader apiReqHeader = ApiReqHeader.builder().setName(headerName)
.setRequired(true).setValue(headerValue).setDesc("header condition").setType("string");
mappingHeaders.add(apiReqHeader);
}
}
}

View File

@ -254,7 +254,26 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
private ApiRequestExample buildReqJson(DocJavaMethod javaMethod, ApiMethodDoc apiMethodDoc, String methodType,
ProjectDocConfigBuilder configBuilder) {
JavaMethod method = javaMethod.getJavaMethod();
Map<String, String> pathParamsMap = new LinkedHashMap<>();
List<JavaAnnotation> methodAnnotations = method.getAnnotations();
for (JavaAnnotation annotation : methodAnnotations) {
String annotationName = annotation.getType().getName();
if (annotationName.contains("Mapping")) {
Object paramsObjects = annotation.getNamedParameter("params");
if (Objects.isNull(paramsObjects)) {
continue;
}
String params = StringUtil.removeQuotes(paramsObjects.toString());
if (!params.startsWith("[")) {
mappingParamProcess(paramsObjects.toString(), pathParamsMap);
continue;
}
List<String> headers = (LinkedList) paramsObjects;
for (String str : headers) {
mappingParamProcess(str, pathParamsMap);
}
}
}
List<JavaParameter> parameterList = method.getParameters();
List<ApiReqHeader> reqHeaderList = apiMethodDoc.getRequestHeaders();
if (parameterList.size() < 1) {
@ -270,7 +289,6 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
Map<String, String> constantsMap = configBuilder.getConstantsMap();
boolean requestFieldToUnderline = configBuilder.getApiConfig().isRequestFieldToUnderline();
Map<String, String> replacementMap = configBuilder.getReplaceClassMap();
Map<String, String> pathParamsMap = new LinkedHashMap<>();
Map<String, String> paramsComments = DocUtil.getParamsComments(method, DocTags.PARAM, null);
List<String> springMvcRequestAnnotations = SpringMvcRequestAnnotationsEnum.listSpringMvcRequestAnnotations();
List<FormData> formDataList = new ArrayList<>();
@ -492,14 +510,34 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
Map<String, String> replacementMap = builder.getReplaceClassMap();
Map<String, String> paramTagMap = DocUtil.getParamsComments(javaMethod, DocTags.PARAM, className);
Map<String, String> paramsComments = DocUtil.getParamsComments(javaMethod, DocTags.PARAM, null);
List<ApiParam> paramList = new ArrayList<>();
Map<String, String> mappingParams = new HashMap<>();
List<JavaAnnotation> methodAnnotations = javaMethod.getAnnotations();
for (JavaAnnotation annotation : methodAnnotations) {
String annotationName = annotation.getType().getName();
if (annotationName.contains("Mapping")) {
Object paramsObjects = annotation.getNamedParameter("params");
if (Objects.isNull(paramsObjects)) {
continue;
}
String params = StringUtil.removeQuotes(paramsObjects.toString());
if (!params.startsWith("[")) {
mappingParamToApiParam(paramsObjects.toString(), paramList, mappingParams);
continue;
}
List<String> headers = (LinkedList) paramsObjects;
for (String str : headers) {
mappingParamToApiParam(str, paramList, mappingParams);
}
}
}
List<JavaParameter> parameterList = javaMethod.getParameters();
if (parameterList.size() < 1) {
return ApiMethodReqParam.builder()
.setPathParams(new ArrayList<>(0))
.setQueryParams(new ArrayList<>(0))
.setQueryParams(paramList)
.setRequestParams(new ArrayList<>(0));
}
List<ApiParam> paramList = new ArrayList<>();
Map<String, String> constantsMap = builder.getConstantsMap();
boolean requestFieldToUnderline = builder.getApiConfig().isRequestFieldToUnderline();
@ -508,6 +546,9 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
out:
for (JavaParameter parameter : parameterList) {
String paramName = parameter.getName();
if (mappingParams.containsKey(paramName)) {
continue;
}
JavaType javaType = parameter.getType();
if (Objects.nonNull(actualTypesMap) && Objects.nonNull(actualTypesMap.get(javaType.getCanonicalName()))) {
javaType = actualTypesMap.get(javaType.getCanonicalName());
@ -783,4 +824,44 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
}
return mockValue;
}
private void mappingParamProcess(String str, Map<String, String> pathParamsMap) {
String param = StringUtil.removeQuotes(str);
String paramName;
String paramValue;
if (param.contains("=")) {
int index = param.indexOf("=");
paramName = param.substring(0, index);
paramValue = param.substring(index + 1);
pathParamsMap.put(paramName, paramValue);
} else {
paramName = param;
pathParamsMap.put(paramName, DocUtil.getValByTypeAndFieldName("string", paramName, Boolean.TRUE));
}
}
private void mappingParamToApiParam(String str, List<ApiParam> paramList, Map<String, String> mappingParams) {
String param = StringUtil.removeQuotes(str);
String paramName;
String paramValue;
if (param.contains("=")) {
int index = param.indexOf("=");
paramName = param.substring(0, index);
paramValue = param.substring(index + 1);
} else {
paramName = param;
paramValue = DocUtil.getValByTypeAndFieldName("string", paramName, Boolean.TRUE);
}
String type = ValidateUtil.isPositiveInteger(paramValue) ? "int32" : "string";
ApiParam apiParam = ApiParam.of().setField(paramName)
.setId(paramList.size() + 1)
.setQueryParam(true)
.setValue(paramValue)
.setType(type).setDesc("parameter condition")
.setRequired(true)
.setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(apiParam);
mappingParams.put(paramName, null);
}
}

File diff suppressed because one or more lines are too long