Add param value set

This commit is contained in:
oppofind 2020-11-16 23:16:05 +08:00
parent d8b84f4eb5
commit 270c3b76fa
3 changed files with 53 additions and 14 deletions

View File

@ -163,7 +163,7 @@ public class OpenApiBuilder {
List<ApiParam> apiParams = apiMethodDoc.getRequestParams();
//去除pathVariable参数
size = (int) apiParams.stream()
.filter(apiParam -> !apiParam.isPathParams()).count();
.filter(apiParam -> !apiParam.isPathParam()).count();
}
boolean isPost = (apiMethodDoc.getType().equals(Methods.POST.getValue()) || apiMethodDoc.getType().equals(Methods.PUT.getValue()) ||
apiMethodDoc.getType().equals(Methods.PATCH.getValue())) && size > 0;
@ -267,7 +267,7 @@ public class OpenApiBuilder {
parameters.put("description", apiParam.getDesc());
parameters.put("required", apiParam.isRequired());
parameters.put("schema", buildParametersSchema(apiParam));
if (apiParam.isPathParams()) {
if (apiParam.isPathParam()) {
parameters.put("in", "path");
} else {
parameters.put("in", "query");

View File

@ -67,7 +67,17 @@ public class ApiParam {
/**
* PathVariableParams flag
*/
private boolean isPathParams;
private boolean pathParam;
/**
* query params flag
*/
private boolean queryParam;
/**
*
*/
private String value;
/**
* children params
@ -145,12 +155,21 @@ public class ApiParam {
return children;
}
public boolean isPathParams() {
return isPathParams;
public boolean isPathParam() {
return pathParam;
}
public ApiParam setPathParams(boolean pathParams) {
isPathParams = pathParams;
public ApiParam setPathParam(boolean pathParam) {
this.pathParam = pathParam;
return this;
}
public boolean isQueryParam() {
return queryParam;
}
public ApiParam setQueryParam(boolean queryParam) {
this.queryParam = queryParam;
return this;
}
@ -159,6 +178,15 @@ public class ApiParam {
return this;
}
public String getValue() {
return value;
}
public ApiParam setValue(String value) {
this.value = value;
return this;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
@ -176,8 +204,10 @@ public class ApiParam {
.append(version).append('\"');
sb.append(",\"pid\":")
.append(pid);
sb.append(",\"isPathParams\":")
.append(isPathParams);
sb.append(",\"pathParam\":")
.append(pathParam);
sb.append(",\"queryParam\":")
.append(queryParam);
sb.append(",\"children\":")
.append(children);
sb.append('}');

View File

@ -491,7 +491,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
//file upload
if (typeName.contains(DocGlobalConstants.MULTIPART_FILE_FULLY)) {
ApiParam param = ApiParam.of().setField(paramName).setType("file")
.setId(paramList.size() + 1)
.setId(paramList.size() + 1).setQueryParam(true)
.setDesc(comment).setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
continue;
@ -536,10 +536,12 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
}
}
boolean required = Boolean.parseBoolean(strRequired);
boolean queryParam = false;
if (isPathVariable) {
comment = comment + " (This is path parameter.)";
} else if (!isRequestBody && requestBodyCounter > 0) {
comment = comment + " (This is query parameter.)";
queryParam = true;
}
if (JavaClassValidateUtil.isCollection(fullTypeName) || JavaClassValidateUtil.isArray(fullTypeName)) {
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
@ -551,7 +553,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
String shortSimple = DocClassUtil.processTypeNameForParams(gicName);
ApiParam param = ApiParam.of().setField(paramName).setDesc(comment + ",[array of " + shortSimple + "]")
.setRequired(required)
.setPathParams(isPathVariable)
.setPathParam(isPathVariable)
.setQueryParam(queryParam)
.setId(paramList.size() + 1)
.setType("array");
paramList.add(param);
@ -566,17 +569,21 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
}
}
} else if (JavaClassValidateUtil.isPrimitive(fullTypeName)) {
String typeSimpleName = DocClassUtil.processTypeNameForParams(simpleName);
String value = DocUtil.getValByTypeAndFieldName(typeSimpleName, paramName);
ApiParam param = ApiParam.of().setField(paramName)
.setType(DocClassUtil.processTypeNameForParams(simpleName))
.setId(paramList.size() + 1)
.setPathParams(isPathVariable)
.setPathParam(isPathVariable)
.setQueryParam(queryParam).setValue(value)
.setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
} else if (JavaClassValidateUtil.isMap(fullTypeName)) {
if (DocGlobalConstants.JAVA_MAP_FULLY.equals(typeName)) {
ApiParam apiParam = ApiParam.of().setField(paramName).setType("map")
.setId(paramList.size() + 1)
.setPathParams(isPathVariable)
.setPathParam(isPathVariable)
.setQueryParam(queryParam)
.setDesc(comment).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(apiParam);
continue;
@ -587,9 +594,11 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
// param is enum
else if (javaClass.isEnum()) {
String o = JavaClassUtil.getEnumParams(javaClass);
Object value = JavaClassUtil.getEnumValue(javaClass, Boolean.FALSE);
ApiParam param = ApiParam.of().setField(paramName)
.setId(paramList.size() + 1)
.setPathParams(isPathVariable)
.setPathParam(isPathVariable)
.setQueryParam(queryParam).setValue(String.valueOf(value))
.setType("enum").setDesc(StringUtil.removeQuotes(o)).setRequired(required).setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
} else {