diff --git a/src/main/java/com/power/doc/builder/OpenApiBuilder.java b/src/main/java/com/power/doc/builder/OpenApiBuilder.java index a08715a..fa56b10 100644 --- a/src/main/java/com/power/doc/builder/OpenApiBuilder.java +++ b/src/main/java/com/power/doc/builder/OpenApiBuilder.java @@ -243,7 +243,12 @@ public class OpenApiBuilder { if (!isRep && apiMethodDoc.getContentType().equals(DocGlobalConstants.MULTIPART_TYPE)) { // formdata Map map = new LinkedHashMap<>(); - map.put("type", "object"); + if(apiMethodDoc.isListParam()) { + map.put("type", DocGlobalConstants.ARRAY); + } + else { + map.put("type", "object"); + } Map properties = new LinkedHashMap<>(); Map detail; for (ApiParam apiParam : apiMethodDoc.getQueryParams()) { @@ -261,7 +266,6 @@ public class OpenApiBuilder { } else { detail.put("format", "binary"); } - } properties.put(apiParam.getField(), detail); } @@ -289,13 +293,11 @@ public class OpenApiBuilder { Map schema = new HashMap<>(10); //当类型为数组时使用 Map innerScheme = new HashMap<>(10); - //去除url中的特殊字符 String responseRef = "#/components/schemas/" + apiMethodDoc.getPath().replaceAll(PATH_REGEX, "_") + "response"; String requestRef = "#/components/schemas/" + apiMethodDoc.getPath().replaceAll(PATH_REGEX, "_") + "request"; - //如果是数组类型 - if(DocGlobalConstants.ARRAY.equals(apiMethodDoc.getType())){ + if(apiMethodDoc.isListParam()){ schema.put("type",DocGlobalConstants.ARRAY); if (isRep) { innerScheme.put("$ref", responseRef); diff --git a/src/main/java/com/power/doc/model/ApiMethodDoc.java b/src/main/java/com/power/doc/model/ApiMethodDoc.java index 8cca309..7197438 100644 --- a/src/main/java/com/power/doc/model/ApiMethodDoc.java +++ b/src/main/java/com/power/doc/model/ApiMethodDoc.java @@ -182,6 +182,19 @@ public class ApiMethodDoc implements Serializable { */ private String page = ""; + /** + * 是否为List数据 openApi + */ + private boolean listParam = false; + + public boolean isListParam() { + return listParam; + } + + public void setListParam(boolean listParam) { + this.listParam = listParam; + } + public String getMethodId() { return methodId; } diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java index c3d9cb5..47e98f2 100644 --- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java @@ -320,6 +320,10 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate { String simpleTypeName = javaType.getValue(); typeName = DocClassUtil.rewriteRequestParam(typeName); gicTypeName = DocClassUtil.rewriteRequestParam(gicTypeName); + //if params is collection + if(JavaClassValidateUtil.isCollection(typeName)){ + apiMethodDoc.setListParam(true); + } JavaClass javaClass = configBuilder.getJavaProjectBuilder().getClassByName(typeName); String[] globGicName = DocClassUtil.getSimpleGicName(gicTypeName); String comment = this.paramCommentResolve(paramsComments.get(paramName)); diff --git a/src/test/java/com/power/doc/ApiDocTest.java b/src/test/java/com/power/doc/ApiDocTest.java index 393a682..88590e5 100644 --- a/src/test/java/com/power/doc/ApiDocTest.java +++ b/src/test/java/com/power/doc/ApiDocTest.java @@ -44,7 +44,8 @@ public class ApiDocTest { //不指定SourcePaths默认加载代码为项目src/main/java下的 config.setSourceCodePaths( SourceCodePath.builder().setDesc("本项目代码") - .setPath("C:\\Users\\xingzi\\Desktop\\api-doc-test\\src\\main\\java") + .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,6 +67,7 @@ public class ApiDocTest { CustomRespField.builder().setName("code").setValue("00000") //.setDesc("响应代码") ); + config.setPackageFilters("com.power.doc.controller.UserController"); //非必须只有当setAllInOne设置为true时文档变更记录才生效,https://gitee.com/sunyurepository/ApplicationPower/issues/IPS4O config.setRevisionLogs( RevisionLog.builder().setRevisionTime("2018/12/15").setAuthor("chen").setRemarks("测试").setStatus("创建").setVersion("V1.0"), @@ -74,9 +76,9 @@ public class ApiDocTest { long start = System.currentTimeMillis(); - // OpenApiBuilder.buildOpenApi(config); - //HtmlApiDocBuilder.buildApiDoc(config); + TornaBuilder.buildApiDoc(config); + OpenApiBuilder.buildOpenApi(config); long end = System.currentTimeMillis(); DateTimeUtil.printRunTime(end, start); }