From ad2bf8013cadb6a54cb7f8091a55f0bff8e57df0 Mon Sep 17 00:00:00 2001 From: shalousun <836575280@qq.com> Date: Sat, 29 Jul 2023 11:39:42 +0800 Subject: [PATCH] release 2.7.4 --- pom.xml | 4 +- .../power/doc/builder/HtmlApiDocBuilder.java | 1 - .../power/doc/builder/PostmanJsonBuilder.java | 48 +++++++++++-------- .../openapi/AbstractOpenApiBuilder.java | 11 +---- .../doc/builder/openapi/OpenApiBuilder.java | 12 ++--- .../doc/builder/openapi/SwaggerBuilder.java | 16 ++----- .../power/doc/constants/JAXRSAnnotations.java | 23 +++++++++ .../power/doc/constants/SolonAnnotations.java | 23 +++++++++ .../power/doc/constants/TornaConstants.java | 2 +- .../json/PropertyNamingStrategies.java | 1 + .../doc/factory/BuildTemplateFactory.java | 2 +- .../doc/function/RequestMappingFunc.java | 6 +++ .../model/framework/PageableAsQueryParam.java | 3 ++ .../power/doc/model/openapi/OpenApiTag.java | 23 +++++++++ .../doc/model/request/JaxrsPathMapping.java | 22 +++++++++ .../doc/template/RpcDocBuildTemplate.java | 31 +++--------- .../power/doc/utils/BeetlTemplateUtil.java | 2 +- .../java/com/power/doc/utils/TornaUtil.java | 23 +++++++++ .../com/power/doc/util/DocPathUtilTest.java | 4 +- 19 files changed, 172 insertions(+), 85 deletions(-) diff --git a/pom.xml b/pom.xml index 04d3e5c2..f59a8608 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 smart-doc jar - 2.7.3 + 2.7.4 smart-doc https://github.com/smart-doc-group/smart-doc.git @@ -46,7 +46,7 @@ com.ibeetl beetl - 3.15.4.RELEASE + 3.15.7.RELEASE com.github.shalousun diff --git a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java index 31d92d0d..219fa28b 100644 --- a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java +++ b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java @@ -62,7 +62,6 @@ public class HtmlApiDocBuilder { private static final String ERROR_CODE_HTML = "error.html"; private static final String DICT_HTML = "dict.html"; - private static final long now = System.currentTimeMillis(); private static String INDEX_HTML = "index.html"; /** diff --git a/src/main/java/com/power/doc/builder/PostmanJsonBuilder.java b/src/main/java/com/power/doc/builder/PostmanJsonBuilder.java index 3427b56e..3a48e634 100644 --- a/src/main/java/com/power/doc/builder/PostmanJsonBuilder.java +++ b/src/main/java/com/power/doc/builder/PostmanJsonBuilder.java @@ -103,10 +103,10 @@ private static ItemBean buildItemBean(ApiDoc apiDoc) { List itemBeans = new ArrayList<>(); List apiMethodDocs = apiDoc.getList(); apiMethodDocs.forEach( - apiMethodDoc -> { - ItemBean itemBean1 = buildItem(apiMethodDoc); - itemBeans.add(itemBean1); - } + apiMethodDoc -> { + ItemBean itemBean1 = buildItem(apiMethodDoc); + itemBeans.add(itemBean1); + } ); itemBean.setItem(itemBeans); return itemBean; @@ -142,11 +142,17 @@ private static UrlBean buildUrlBean(ApiMethodDoc apiMethodDoc) { String url = Optional.ofNullable(apiMethodDoc.getRequestExample().getUrl()).orElse(apiMethodDoc.getUrl()); urlBean.setRaw(DocPathUtil.toPostmanPath(url)); String shortUrl = DocPathUtil.toPostmanPath(apiMethodDoc.getPath()); - String[] paths = shortUrl.split("/"); + String[] paths; + if (StringUtil.isNotEmpty(shortUrl)) { + paths = shortUrl.split("/"); + } else { + paths = new String[0]; + } List pathList = new ArrayList<>(); String serverPath = CollectionUtil.isNotEmpty(urlBean.getPath()) ? urlBean.getPath().get(0) : ""; // Add server path - if (CollectionUtil.isNotEmpty(urlBean.getPath()) && !shortUrl.contains(serverPath)) { + if (CollectionUtil.isNotEmpty(urlBean.getPath()) && StringUtil.isNotEmpty(shortUrl) + && !shortUrl.contains(serverPath)) { String[] serverPaths = serverPath.split("/"); pathList.addAll(Arrays.asList(serverPaths)); } @@ -156,7 +162,7 @@ private static UrlBean buildUrlBean(ApiMethodDoc apiMethodDoc) { pathList.add(str); } } - if (shortUrl.endsWith("/")) { + if (StringUtil.isNotEmpty(shortUrl) && shortUrl.endsWith("/")) { pathList.add(""); } @@ -164,7 +170,7 @@ private static UrlBean buildUrlBean(ApiMethodDoc apiMethodDoc) { List queryParams = new ArrayList<>(); if (!apiMethodDoc.getType().equals(Methods.POST.getValue()) || - apiMethodDoc.getContentType().contains(DocGlobalConstants.JSON_CONTENT_TYPE)) { + apiMethodDoc.getContentType().contains(DocGlobalConstants.JSON_CONTENT_TYPE)) { for (ApiParam apiParam : apiMethodDoc.getQueryParams()) { ParamBean queryParam = new ParamBean(); queryParam.setDescription(apiParam.getDesc()); @@ -236,15 +242,15 @@ private static List buildHeaderBeanList(ApiMethodDoc apiMethodDoc) { List headerBeans = new ArrayList<>(); List headers = apiMethodDoc.getRequestHeaders(); headers.forEach( - apiReqHeader -> { - HeaderBean headerBean = new HeaderBean(); - headerBean.setKey(apiReqHeader.getName()); - headerBean.setName(apiReqHeader.getName()); - headerBean.setValue(apiReqHeader.getValue()); - headerBean.setDisabled(!apiReqHeader.isRequired()); - headerBean.setDescription(apiReqHeader.getDesc()); - headerBeans.add(headerBean); - } + apiReqHeader -> { + HeaderBean headerBean = new HeaderBean(); + headerBean.setKey(apiReqHeader.getName()); + headerBean.setName(apiReqHeader.getName()); + headerBean.setValue(apiReqHeader.getValue()); + headerBean.setDisabled(!apiReqHeader.isRequired()); + headerBean.setDescription(apiReqHeader.getDesc()); + headerBeans.add(headerBean); + } ); return headerBeans; @@ -257,10 +263,10 @@ private static void postManCreate(ApiConfig config, ProjectDocConfigBuilder conf requestItem.setInfo(new InfoBean(config.getProjectName())); List itemBeans = new ArrayList<>(); apiDocList.forEach( - apiDoc -> { - ItemBean itemBean = buildItemBean(apiDoc); - itemBeans.add(itemBean); - } + apiDoc -> { + ItemBean itemBean = buildItemBean(apiDoc); + itemBeans.add(itemBean); + } ); requestItem.setItem(itemBeans); String filePath = config.getOutPath(); diff --git a/src/main/java/com/power/doc/builder/openapi/AbstractOpenApiBuilder.java b/src/main/java/com/power/doc/builder/openapi/AbstractOpenApiBuilder.java index c9bf8897..eb351b7a 100644 --- a/src/main/java/com/power/doc/builder/openapi/AbstractOpenApiBuilder.java +++ b/src/main/java/com/power/doc/builder/openapi/AbstractOpenApiBuilder.java @@ -23,15 +23,6 @@ package com.power.doc.builder.openapi; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - import com.power.common.util.CollectionUtil; import com.power.common.util.StringUtil; import com.power.doc.builder.DocBuilderTemplate; @@ -45,6 +36,8 @@ import com.power.doc.utils.OpenApiSchemaUtil; import com.thoughtworks.qdox.JavaProjectBuilder; +import java.util.*; + import static com.power.doc.constants.DocGlobalConstants.*; diff --git a/src/main/java/com/power/doc/builder/openapi/OpenApiBuilder.java b/src/main/java/com/power/doc/builder/openapi/OpenApiBuilder.java index 4f5f1bf0..fef4be39 100644 --- a/src/main/java/com/power/doc/builder/openapi/OpenApiBuilder.java +++ b/src/main/java/com/power/doc/builder/openapi/OpenApiBuilder.java @@ -22,17 +22,8 @@ */ package com.power.doc.builder.openapi; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - import com.power.common.util.CollectionUtil; import com.power.common.util.FileUtil; -import com.power.common.util.StringUtil; import com.power.doc.constants.DocGlobalConstants; import com.power.doc.constants.Methods; import com.power.doc.helper.JavaProjectBuilderHelper; @@ -43,6 +34,9 @@ import com.thoughtworks.qdox.JavaProjectBuilder; import org.apache.commons.lang3.StringUtils; +import java.util.*; +import java.util.stream.Collectors; + import static com.power.doc.constants.DocGlobalConstants.*; /** diff --git a/src/main/java/com/power/doc/builder/openapi/SwaggerBuilder.java b/src/main/java/com/power/doc/builder/openapi/SwaggerBuilder.java index 71b990a1..cec48cbc 100644 --- a/src/main/java/com/power/doc/builder/openapi/SwaggerBuilder.java +++ b/src/main/java/com/power/doc/builder/openapi/SwaggerBuilder.java @@ -22,31 +22,21 @@ */ package com.power.doc.builder.openapi; -import java.util.*; - import com.power.common.util.CollectionUtil; import com.power.common.util.FileUtil; import com.power.common.util.StringUtil; -import com.power.doc.builder.DocBuilderTemplate; -import com.power.doc.builder.ProjectDocConfigBuilder; import com.power.doc.constants.DocGlobalConstants; -import com.power.doc.factory.BuildTemplateFactory; import com.power.doc.helper.JavaProjectBuilderHelper; -import com.power.doc.model.ApiConfig; -import com.power.doc.model.ApiDoc; -import com.power.doc.model.ApiGroup; -import com.power.doc.model.ApiMethodDoc; -import com.power.doc.model.ApiParam; -import com.power.doc.model.ApiReqParam; +import com.power.doc.model.*; import com.power.doc.model.openapi.OpenApiTag; -import com.power.doc.template.IDocBuildTemplate; import com.power.doc.utils.DocUtil; import com.power.doc.utils.JsonUtil; import com.power.doc.utils.OpenApiSchemaUtil; import com.thoughtworks.qdox.JavaProjectBuilder; -import com.thoughtworks.qdox.model.JavaClass; import org.apache.commons.lang3.StringUtils; +import java.util.*; + import static com.power.doc.constants.DocGlobalConstants.*; diff --git a/src/main/java/com/power/doc/constants/JAXRSAnnotations.java b/src/main/java/com/power/doc/constants/JAXRSAnnotations.java index 9d404c0f..a9489046 100644 --- a/src/main/java/com/power/doc/constants/JAXRSAnnotations.java +++ b/src/main/java/com/power/doc/constants/JAXRSAnnotations.java @@ -1,3 +1,26 @@ +/* + * smart-doc https://github.com/smart-doc-group/smart-doc + * + * Copyright (C) 2018-2023 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package com.power.doc.constants; /** diff --git a/src/main/java/com/power/doc/constants/SolonAnnotations.java b/src/main/java/com/power/doc/constants/SolonAnnotations.java index 1a6b76e8..ac0b511e 100644 --- a/src/main/java/com/power/doc/constants/SolonAnnotations.java +++ b/src/main/java/com/power/doc/constants/SolonAnnotations.java @@ -1,3 +1,26 @@ +/* + * smart-doc https://github.com/smart-doc-group/smart-doc + * + * Copyright (C) 2018-2023 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package com.power.doc.constants; /** diff --git a/src/main/java/com/power/doc/constants/TornaConstants.java b/src/main/java/com/power/doc/constants/TornaConstants.java index 2e882976..237caa06 100644 --- a/src/main/java/com/power/doc/constants/TornaConstants.java +++ b/src/main/java/com/power/doc/constants/TornaConstants.java @@ -44,7 +44,6 @@ */ public class TornaConstants { - public static final String ID = "id"; public static final String CODE = "code"; public static final String MESSAGE = "msg"; @@ -62,6 +61,7 @@ public class TornaConstants { public static final String PUSH = "doc.push"; public static final String ENUM_PUSH = "enum.batch.push"; + /** * torna文件数组类型 */ diff --git a/src/main/java/com/power/doc/extension/json/PropertyNamingStrategies.java b/src/main/java/com/power/doc/extension/json/PropertyNamingStrategies.java index 1d167ba9..8a5d03da 100644 --- a/src/main/java/com/power/doc/extension/json/PropertyNamingStrategies.java +++ b/src/main/java/com/power/doc/extension/json/PropertyNamingStrategies.java @@ -1,3 +1,4 @@ + package com.power.doc.extension.json; diff --git a/src/main/java/com/power/doc/factory/BuildTemplateFactory.java b/src/main/java/com/power/doc/factory/BuildTemplateFactory.java index 5142fd47..2869d8da 100644 --- a/src/main/java/com/power/doc/factory/BuildTemplateFactory.java +++ b/src/main/java/com/power/doc/factory/BuildTemplateFactory.java @@ -47,7 +47,7 @@ public static IDocBuildTemplate getDocBuildTemplate(String framework) { e.printStackTrace(); } catch (ClassNotFoundException e) { throw new RuntimeException( - "The class=>" + className + " is not found , smart-doc currently supported framework name can only be set in [dubbo, spring]."); + "The class=>" + className + " is not found , smart-doc currently supported framework name can only be set in [dubbo, spring,solon,JAX-RS]."); } return null; } diff --git a/src/main/java/com/power/doc/function/RequestMappingFunc.java b/src/main/java/com/power/doc/function/RequestMappingFunc.java index d160acd3..a8dc450c 100644 --- a/src/main/java/com/power/doc/function/RequestMappingFunc.java +++ b/src/main/java/com/power/doc/function/RequestMappingFunc.java @@ -25,6 +25,12 @@ import com.power.doc.model.request.RequestMapping; import com.thoughtworks.qdox.model.JavaClass; + +/** + * beetl template function + * @author yu 2022/12/02. + */ + @FunctionalInterface public interface RequestMappingFunc { diff --git a/src/main/java/com/power/doc/model/framework/PageableAsQueryParam.java b/src/main/java/com/power/doc/model/framework/PageableAsQueryParam.java index 3327a5c0..cc957753 100644 --- a/src/main/java/com/power/doc/model/framework/PageableAsQueryParam.java +++ b/src/main/java/com/power/doc/model/framework/PageableAsQueryParam.java @@ -22,6 +22,9 @@ */ package com.power.doc.model.framework; +/** + * @author yusun 2021/06/30. + */ public class PageableAsQueryParam { /** diff --git a/src/main/java/com/power/doc/model/openapi/OpenApiTag.java b/src/main/java/com/power/doc/model/openapi/OpenApiTag.java index e04ad686..865fe8e4 100644 --- a/src/main/java/com/power/doc/model/openapi/OpenApiTag.java +++ b/src/main/java/com/power/doc/model/openapi/OpenApiTag.java @@ -1,3 +1,26 @@ +/* + * smart-doc https://github.com/smart-doc-group/smart-doc + * + * Copyright (C) 2018-2023 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package com.power.doc.model.openapi; import java.util.Objects; diff --git a/src/main/java/com/power/doc/model/request/JaxrsPathMapping.java b/src/main/java/com/power/doc/model/request/JaxrsPathMapping.java index f774d978..5ed56efb 100644 --- a/src/main/java/com/power/doc/model/request/JaxrsPathMapping.java +++ b/src/main/java/com/power/doc/model/request/JaxrsPathMapping.java @@ -1,3 +1,25 @@ +/* + * smart-doc https://github.com/smart-doc-group/smart-doc + * + * Copyright (C) 2018-2023 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package com.power.doc.model.request; /** diff --git a/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java b/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java index fce8bf85..fe71db43 100644 --- a/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java +++ b/src/main/java/com/power/doc/template/RpcDocBuildTemplate.java @@ -22,21 +22,9 @@ */ package com.power.doc.template; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - import com.power.common.util.StringUtil; import com.power.common.util.ValidateUtil; import com.power.doc.builder.ProjectDocConfigBuilder; -import com.power.doc.constants.DocAnnotationConstants; import com.power.doc.constants.DocGlobalConstants; import com.power.doc.constants.DocTags; import com.power.doc.constants.DubboAnnotationConstants; @@ -47,20 +35,13 @@ import com.power.doc.model.RpcJavaMethod; import com.power.doc.model.annotation.FrameworkAnnotations; import com.power.doc.model.rpc.RpcApiDoc; -import com.power.doc.utils.ApiParamTreeUtil; -import com.power.doc.utils.DocClassUtil; -import com.power.doc.utils.DocUtil; -import com.power.doc.utils.JavaClassUtil; -import com.power.doc.utils.JavaClassValidateUtil; -import com.power.doc.utils.JavaFieldUtil; -import com.thoughtworks.qdox.model.DocletTag; -import com.thoughtworks.qdox.model.JavaAnnotation; -import com.thoughtworks.qdox.model.JavaClass; -import com.thoughtworks.qdox.model.JavaMethod; -import com.thoughtworks.qdox.model.JavaParameter; -import com.thoughtworks.qdox.model.JavaType; +import com.power.doc.utils.*; +import com.thoughtworks.qdox.model.*; + +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; -import static com.power.doc.constants.DocTags.DEPRECATED; import static com.power.doc.constants.DocTags.IGNORE; /** diff --git a/src/main/java/com/power/doc/utils/BeetlTemplateUtil.java b/src/main/java/com/power/doc/utils/BeetlTemplateUtil.java index b7d50a31..a1383218 100644 --- a/src/main/java/com/power/doc/utils/BeetlTemplateUtil.java +++ b/src/main/java/com/power/doc/utils/BeetlTemplateUtil.java @@ -1,7 +1,7 @@ /* * smart-doc * - * Copyright (C) 2016-2021 smart-doc + * Copyright (C) 2018-2023 smart-doc * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/src/main/java/com/power/doc/utils/TornaUtil.java b/src/main/java/com/power/doc/utils/TornaUtil.java index 74566423..8660dba2 100644 --- a/src/main/java/com/power/doc/utils/TornaUtil.java +++ b/src/main/java/com/power/doc/utils/TornaUtil.java @@ -1,3 +1,26 @@ +/* + * smart-doc https://github.com/smart-doc-group/smart-doc + * + * Copyright (C) 2018-2023 smart-doc + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package com.power.doc.utils; import java.util.ArrayList; diff --git a/src/test/java/com/power/doc/util/DocPathUtilTest.java b/src/test/java/com/power/doc/util/DocPathUtilTest.java index 352e37d0..a17d2218 100644 --- a/src/test/java/com/power/doc/util/DocPathUtilTest.java +++ b/src/test/java/com/power/doc/util/DocPathUtilTest.java @@ -12,8 +12,8 @@ public class DocPathUtilTest { @Test public void testMatches() { - String a= System.getProperty(DocGlobalConstants.DOC_LANGUAGE); - Boolean flag = Boolean.parseBoolean(a); + String a = System.getProperty(DocGlobalConstants.DOC_LANGUAGE); + Boolean flag = Boolean.parseBoolean(a); System.out.println(flag); String pattern = "/app/page/**"; String path = "/app/page/{pageIndex}/{pageSize}/{ag}";