Skip to content

Commit 9033847

Browse files
dependabot[bot]xingzi
authored and
xingzi
committed
parent afb76ed
author dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 1740961143 +0000 committer xingzi <[email protected]> 1747553933 +0800 parent afb76ed author dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 1740961143 +0000 committer xingzi <[email protected]> 1747553897 +0800 chore(deps): bump com.ibeetl:beetl from 3.19.0.RELEASE to 3.19.1.RELEASE Bumps com.ibeetl:beetl from 3.19.0.RELEASE to 3.19.1.RELEASE. --- updated-dependencies: - dependency-name: com.ibeetl:beetl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]>
1 parent afb76ed commit 9033847

16 files changed

+423
-44
lines changed

CONTRIBUTING.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Contributing
2+
3+
Thank you for your interest in contributing to `smart-doc`! For detailed guidelines on how to contribute, please review our official [**Contribution Guide**](https://smart-doc-group.github.io/guide/community/contributing).
4+
5+
## Key Highlights
6+
Before submitting a Pull Request (PR), please ensure:
7+
- 📌 **Discuss new features**: Start with an [Issue](https://github.com/smart-doc-group/smart-doc/issues) to align on proposed changes.
8+
- 🧩 **Single-focused PRs**: Submit one fix or feature per PR to simplify reviews.
9+
- 🌍 **English comments**: Use English for code comments to support international collaboration.
10+
-**Code quality**: Follow the [Spring Java Format](https://github.com/spring-io/java-format) style and add unit tests.
11+
- 📄 **Update documentation**: Reflect your changes in relevant documentation [`smart-doc-group.github.io`](https://github.com/smart-doc-group/smart-doc-group.github.io/tree/master/docs). if needed.
12+
13+
## Documentation and Examples
14+
If your contribution involves:
15+
- 🛠️ **Configuration changes**:
16+
- Check if your PR adds or modifies configurations (e.g., new parameters, default value updates).
17+
- Update or add corresponding documentation in the [`smart-doc-group.github.io`](https://github.com/smart-doc-group/smart-doc-group.github.io/tree/master/docs).
18+
- 📚 **New features**:
19+
- Provide usage examples in the [`smart-doc-example-cn`](https://github.com/smart-doc-group/smart-doc-example-cn) repository to demonstrate implementation.
20+
21+
22+
## How to Contribute
23+
1. Fork the repository and clone it locally.
24+
2. Create a new branch for your changes.
25+
3. Test your modifications using `smart-doc` (see [Quick Start](https://smart-doc-group.github.io/guide/getting-started)).
26+
4. Format code with `mvn spring-javaformat:apply`.
27+
5. Submit a PR to the main repository.
28+
29+
## Community Engagement
30+
- 📰 Share your use cases or articles in the [Discussions](https://github.com/smart-doc-group/smart-doc/discussions) section.
31+
- ❓ Help answer questions in the `Help` category.
32+
- 💡 Propose ideas or showcase tools in `Ideas` or `Show and tell`.
33+
34+
Your contributions are vital to making `smart-doc` better for everyone. Thank you!

CONTRIBUTING_CN.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 贡献指南
2+
3+
感谢您对参与 `smart-doc` 贡献的兴趣!详细的贡献指引请参考我们的官方 [**贡献指南文档**](https://smart-doc-group.github.io/zh/guide/community/contributing)
4+
5+
## 核心要求
6+
提交 Pull Request (PR) 前请确保:
7+
- 📌 **新功能需先讨论**:通过 [Issue](https://github.com/smart-doc-group/smart-doc/issues) 与社区对齐需求,避免重复劳动。
8+
- 🧩 **单焦点 PR**:每次提交仅包含一个修复或功能,简化代码审查。
9+
- 🌍 **英文注释**:代码注释使用英文,支持国际化协作。
10+
-**代码质量**:遵循 [Spring Java Format](https://github.com/spring-io/java-format) 风格,添加单元测试。
11+
- 📄 **文档同步更新**:若涉及功能变更,请同步更新 [`smart-doc-group.github.io`](https://github.com/smart-doc-group/smart-doc-group.github.io/tree/master/docs) 文档。
12+
13+
## 文档与示例要求
14+
若贡献包含以下内容:
15+
- 🛠️ **配置项变更**
16+
- 检查 PR 是否新增/修改配置(如新增参数、修改默认值)。
17+
- 在 [`smart-doc-group.github.io`](https://github.com/smart-doc-group/smart-doc-group.github.io/tree/master/docs) 中补充或更新对应文档。
18+
- 📚 **新功能实现**
19+
- 在 [`smart-doc-example-cn`](https://github.com/smart-doc-group/smart-doc-example-cn) 仓库提供使用示例,便于其他用户快速理解。
20+
21+
## 贡献步骤
22+
1. Fork 仓库并本地克隆。
23+
2. 创建新分支进行修改。
24+
3. 使用 `smart-doc` 测试改动(参考 [快速入门](https://smart-doc-group.github.io/zh/guide/getting-started))。
25+
4. 执行 `mvn spring-javaformat:apply` 格式化代码。
26+
5. 向主仓库提交 PR。
27+
28+
## 社区互动
29+
- 📰 在 [Discussions](https://github.com/smart-doc-group/smart-doc/discussions) 分享使用案例或技术文章。
30+
- ❓ 在 `Help` 分类帮助解答用户疑问。
31+
- 💡 在 `Ideas``Show and tell` 提出建议或展示相关工具。
32+
33+
您的贡献将帮助 `smart-doc` 更好地服务全球开发者!感谢支持!

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<artifactId>smart-doc</artifactId>
77
<packaging>jar</packaging>
8-
<version>3.0.9</version>
8+
<version>3.1.0</version>
99

1010
<name>smart-doc</name>
1111
<url>https://github.com/TongchengOpenSource/smart-doc.git</url>
@@ -36,14 +36,14 @@
3636
<properties>
3737
<java.version>1.8</java.version>
3838
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
39-
<junit.jupiter.version>5.12.0</junit.jupiter.version>
40-
<beetl.version>3.19.0.RELEASE</beetl.version>
39+
<junit.jupiter.version>5.12.2</junit.jupiter.version>
40+
<beetl.version>3.19.1.RELEASE</beetl.version>
4141
<common-util.version>2.2.8</common-util.version>
4242
<qdox.version>2.0.3.5</qdox.version>
4343
<datafaker.version>1.4.0</datafaker.version>
44-
<gson.version>2.12.1</gson.version>
44+
<gson.version>2.13.1</gson.version>
4545
<eclipse.jgit.version>5.13.3.202401111512-r</eclipse.jgit.version>
46-
<slf4j-api.version>2.0.16</slf4j-api.version>
46+
<slf4j-api.version>2.0.17</slf4j-api.version>
4747

4848
<!-- plugin version -->
4949
<maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>

src/main/java/com/ly/doc/builder/openapi/AbstractOpenApiBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public Map<String, Object> buildPaths(ApiConfig apiConfig, ApiSchema<ApiDoc> api
155155
String[] paths = methodDoc.getPath().split(";");
156156
for (String path : paths) {
157157
path = path.trim();
158+
if (StringUtil.isNotEmpty(apiConfig.getPathPrefix())) {
159+
path = path.replace(apiConfig.getPathPrefix(), "");
160+
}
158161
Map<String, Object> request = this.buildPathUrls(apiConfig, methodDoc, methodDoc.getClazzDoc(),
159162
apiSchema.getApiExceptionStatuses());
160163
if (!pathMap.containsKey(path)) {
@@ -471,6 +474,7 @@ public Map<String, Object> buildProperties(List<ApiParam> apiParam, Map<String,
471474
propertiesData.put(field, this.buildPropertiesData(param, component, isResp));
472475
}
473476
if (!propertiesData.isEmpty()) {
477+
properties.put("type", "object");
474478
properties.put("properties", propertiesData);
475479
}
476480
if (!CollectionUtil.isEmpty(requiredList)) {
@@ -617,4 +621,4 @@ public ApiSchema<ApiDoc> getOpenApiDocs(ApiConfig config, JavaProjectBuilder pro
617621
return docBuildTemplate.getApiData(configBuilder);
618622
}
619623

620-
}
624+
}

src/main/java/com/ly/doc/builder/openapi/OpenApiBuilder.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.commons.lang3.StringUtils;
3737

3838
import java.util.*;
39-
import java.util.stream.Collectors;
4039

4140
/**
4241
*
@@ -52,6 +51,11 @@ public class OpenApiBuilder extends AbstractOpenApiBuilder {
5251
*/
5352
private static final OpenApiBuilder INSTANCE = new OpenApiBuilder();
5453

54+
/**
55+
* OperationId OrderNo Map
56+
*/
57+
private static final Map<String, Integer> OPERATIONID_ORDER_NO_MAP = new HashMap<>();
58+
5559
/**
5660
* private constructor
5761
*/
@@ -148,8 +152,19 @@ public Map<String, Object> buildPathUrlsRequest(ApiConfig apiConfig, ApiMethodDo
148152
request.put("deprecated", apiMethodDoc.isDeprecated());
149153
List<String> paths = OpenApiSchemaUtil.getPatternResult("[A-Za-z0-9_{}]*", apiMethodDoc.getPath());
150154
paths.add(apiMethodDoc.getType());
151-
String operationId = paths.stream().filter(StringUtils::isNotEmpty).collect(Collectors.joining("-"));
152-
request.put("operationId", operationId);
155+
156+
// add operationId
157+
String methodName = apiMethodDoc.getMethodName();
158+
if (OPERATIONID_ORDER_NO_MAP.containsKey(methodName)) {
159+
int order = OPERATIONID_ORDER_NO_MAP.get(methodName);
160+
request.put("operationId", methodName + "_" + order);
161+
OPERATIONID_ORDER_NO_MAP.put(methodName, order + 1);
162+
}
163+
else {
164+
request.put("operationId", methodName);
165+
OPERATIONID_ORDER_NO_MAP.put(methodName, 1);
166+
}
167+
153168
// add extension attribution
154169
if (apiMethodDoc.getExtensions() != null) {
155170
apiMethodDoc.getExtensions().forEach((key, value) -> request.put("x-" + key, value));

src/main/java/com/ly/doc/constants/DocValidatorAnnotationEnum.java

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@
1818
* specific language governing permissions and limitations
1919
* under the License.
2020
*/
21+
2122
package com.ly.doc.constants;
2223

24+
import java.util.Collections;
25+
import java.util.HashMap;
2326
import java.util.HashSet;
27+
import java.util.Map;
2428
import java.util.Set;
2529

2630
/**
27-
* spring validator annotations
31+
* Enumeration of Spring validator annotations with metadata for documentation generation.
32+
* <p>
33+
* This enum maps validation annotations to their default attribute values, enabling
34+
* automatic replacement of placeholders in validation messages (e.g., {min}, {max}).
2835
*
2936
* @author yu 2019/9/19.
3037
*/
31-
public enum DocValidatorAnnotationEnum {
38+
public enum DocValidatorAnnotationEnum implements ValidationAnnotationDefaultsProvider {
3239

3340
/**
3441
* Spring validator annotations `@NotEmpty`
@@ -83,7 +90,15 @@ public enum DocValidatorAnnotationEnum {
8390
/**
8491
* Spring validator annotations `@Size`
8592
*/
86-
SIZE(JSRAnnotationConstants.SIZE),
93+
SIZE(JSRAnnotationConstants.SIZE) {
94+
public Map<String, String> getDefaultProperties() {
95+
// @Size default values (min=0, max=Integer.MAX_VALUE)
96+
Map<String, String> sizeDefaults = new HashMap<>(2);
97+
sizeDefaults.put("min", "0");
98+
sizeDefaults.put("max", Integer.toString(Integer.MAX_VALUE));
99+
return sizeDefaults;
100+
}
101+
},
87102

88103
/**
89104
* Spring validator annotations `@Digits`
@@ -143,17 +158,34 @@ public enum DocValidatorAnnotationEnum {
143158
/**
144159
* Spring validator annotations `@Length`
145160
*/
146-
LENGTH(JSRAnnotationConstants.LENGTH),
161+
LENGTH(JSRAnnotationConstants.LENGTH) {
162+
public Map<String, String> getDefaultProperties() {
163+
// @Length default values (min=0, max=Integer.MAX_VALUE)
164+
Map<String, String> lengthDefaults = new HashMap<>(2);
165+
lengthDefaults.put("min", "0");
166+
lengthDefaults.put("max", Integer.toString(Integer.MAX_VALUE));
167+
return lengthDefaults;
168+
}
169+
},
147170

148171
/**
149172
* Spring validator annotations `@Range`
150173
*/
151-
RANGE(JSRAnnotationConstants.RANGE),
174+
RANGE(JSRAnnotationConstants.RANGE) {
175+
@Override
176+
public Map<String, String> getDefaultProperties() {
177+
// @Range default values (min=0, max=Long.MAX_VALUE)
178+
Map<String, String> rangeDefaults = new HashMap<>(2);
179+
rangeDefaults.put("min", "0");
180+
rangeDefaults.put("max", Long.toString(Long.MAX_VALUE));
181+
return rangeDefaults;
182+
}
183+
},
152184

153185
/**
154186
* Spring validator annotations `@Validated`
155187
*/
156-
VALIDATED(JSRAnnotationConstants.VALIDATED);
188+
VALIDATED(JSRAnnotationConstants.VALIDATED),;
157189

158190
/**
159191
* annotation value
@@ -186,4 +218,30 @@ public enum DocValidatorAnnotationEnum {
186218
EXCLUDED_ANNOTATIONS.add(VALIDATED.value);
187219
}
188220

221+
/**
222+
* Looks up and returns the default attribute values for a validation annotation.
223+
* <p>
224+
* This method iterates through all {@link DocValidatorAnnotationEnum} entries to find
225+
* the matching annotation definition. If found, returns the associated default values
226+
* from {@link ValidationAnnotationDefaultsProvider#getDefaultProperties()}.
227+
* @param annotationName Fully qualified class name of the annotation (e.g.,
228+
* "javax.validation.constraints.Min")
229+
* @return An unmodifiable map of default attribute name-value pairs. Returns an empty
230+
* map if:
231+
* <ul>
232+
* <li>No matching annotation is found</li>
233+
* <li>The annotation does not define default values</li>
234+
* </ul>
235+
* @see DocValidatorAnnotationEnum
236+
* @see ValidationAnnotationDefaultsProvider
237+
*/
238+
public static Map<String, String> getDefaults(String annotationName) {
239+
for (DocValidatorAnnotationEnum entry : values()) {
240+
if (entry.value.equals(annotationName)) {
241+
return entry.getDefaultProperties();
242+
}
243+
}
244+
return Collections.emptyMap();
245+
}
246+
189247
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* smart-doc
3+
*
4+
* Copyright (C) 2018-2025 smart-doc
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one
7+
* or more contributor license agreements. See the NOTICE file
8+
* distributed with this work for additional information
9+
* regarding copyright ownership. The ASF licenses this file
10+
* to you under the Apache License, Version 2.0 (the
11+
* "License"); you may not use this file except in compliance
12+
* with the License. You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing,
17+
* software distributed under the License is distributed on an
18+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19+
* KIND, either express or implied. See the License for the
20+
* specific language governing permissions and limitations
21+
* under the License.
22+
*/
23+
24+
package com.ly.doc.constants;
25+
26+
import java.util.Collections;
27+
import java.util.Map;
28+
29+
/**
30+
* Provides default attribute values for validation annotations.
31+
* <p>
32+
* Implementations of this interface should return immutable maps containing the default
33+
* values for validation annotation attributes. These defaults are used for placeholder
34+
* resolution in validation messages (e.g., replacing {min} with the actual default value
35+
* from the annotation).
36+
*/
37+
public interface ValidationAnnotationDefaultsProvider {
38+
39+
/**
40+
* Gets the default attribute values for the associated validation annotation.
41+
* <p>
42+
* The returned map should be immutable and contain only primitive/wrapper values
43+
* converted to their String representations. Implementations should return an empty
44+
* map if no defaults are available.
45+
* @return Unmodifiable map of default attribute values, or empty map if none exist
46+
*/
47+
default Map<String, String> getDefaultProperties() {
48+
return Collections.emptyMap();
49+
}
50+
51+
/**
52+
* Checks if the annotation has any default property values defined.
53+
* @return true if default properties are available, false otherwise
54+
*/
55+
default boolean hasDefaults() {
56+
return !this.getDefaultProperties().isEmpty();
57+
}
58+
59+
}

src/main/java/com/ly/doc/function/HtmlEscape.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,47 @@
2525
import org.beetl.core.Context;
2626
import org.beetl.core.Function;
2727

28+
import java.util.HashMap;
29+
import java.util.Map;
30+
2831
/**
29-
* beetl template function
32+
* Function to escape HTML content in Beetl templates.
33+
* <p>
34+
* This class provides a method to replace specific HTML characters with their
35+
* corresponding escape sequences and clean up comments.
36+
* <p>
37+
* For example, it replaces:
38+
* <p>
39+
* - <code>"</code> with <code>&amp;quot;</code>
3040
*
31-
* @author yu 2021/6/26.
41+
* @author yu
42+
* @since 2021/6/26
3243
*/
3344
public class HtmlEscape implements Function {
3445

46+
/**
47+
* Map to hold HTML escape sequences.
48+
*/
49+
private static final Map<String, String> HTML_ESCAPE_MAP;
50+
51+
static {
52+
HTML_ESCAPE_MAP = new HashMap<>();
53+
HTML_ESCAPE_MAP.put("<p>", "");
54+
HTML_ESCAPE_MAP.put("</p>", " ");
55+
}
56+
3557
@Override
36-
public String call(Object[] paras, Context ctx) {
37-
String str = String.valueOf(paras[0]).replaceAll("&", "&amp;");
38-
str = str.replaceAll("\"", "&quot;");
39-
str = str.replaceAll("<p>", "").replaceAll("</p>", " ");
40-
return DocUtil.replaceNewLineToHtmlBr(DocUtil.getEscapeAndCleanComment(str));
58+
public String call(Object[] params, Context ctx) {
59+
if (params == null || params.length == 0 || params[0] == null) {
60+
return "";
61+
}
62+
String html = String.valueOf(params[0]);
63+
for (Map.Entry<String, String> entry : HTML_ESCAPE_MAP.entrySet()) {
64+
html = html.replace(entry.getKey(), entry.getValue());
65+
}
66+
67+
html = DocUtil.getEscapeAndCleanComment(html);
68+
return DocUtil.replaceNewLineToHtmlBr(html);
4169
}
4270

4371
}

0 commit comments

Comments
 (0)