Skip to content

Commit 0b719ce

Browse files
[maven-tool] 对于默认的参数值,若为空,不添加该值
1 parent b9f0f86 commit 0b719ce

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

framework/fel/java/maven-plugins/tool-maven-plugin/src/main/java/modelengine/fel/maven/complie/parser/ByteBuddySchemaParser.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222
import static modelengine.fitframework.inspection.Validation.notNull;
2323

24-
import java.util.ArrayList;
2524
import java.util.Arrays;
26-
import java.util.Collections;
2725
import java.util.LinkedHashMap;
2826
import java.util.LinkedList;
2927
import java.util.List;
@@ -79,7 +77,9 @@ private static Map<String, Object> getStringObjectMap(ReturnPropertyEntity retur
7977
if (returnPropertyEntity.getConvertor() != null) {
8078
returnProperty.put("convertor", returnPropertyEntity.getConvertor());
8179
}
82-
returnProperty.put("examples", returnPropertyEntity.getExamples());
80+
if (returnPropertyEntity.getExamples() != null) {
81+
returnProperty.put("examples", returnPropertyEntity.getExamples());
82+
}
8383
return returnProperty;
8484
}
8585

@@ -92,7 +92,7 @@ private static ParameterEntity parseParameter(MethodDescription methodDescriptio
9292
String methodName = parameterDescription.getName();
9393
PropertyEntity property = parseProperty(parameterDescription);
9494
properties.put(methodName, property);
95-
if (property.isNeed()) {
95+
if (property.isRequired()) {
9696
required.add(methodName);
9797
}
9898
}
@@ -112,9 +112,15 @@ private static PropertyEntity parseProperty(ParameterDescription parameterDescri
112112
if (paramAnnotation != null) {
113113
Property property = paramAnnotation.load();
114114
entity.setDescription(property.description());
115-
entity.setNeed(property.required());
116-
entity.setDefaultValue(property.defaultValue());
117-
entity.setExamples(Collections.singletonList(property.example()));
115+
entity.setRequired(property.required());
116+
// 只有当 defaultValue 不为空字符串时才设置
117+
if (!property.defaultValue().isEmpty()) {
118+
entity.setDefaultValue(property.defaultValue());
119+
}
120+
// 只有当 example 不为空字符串时才设置
121+
if (!property.example().isEmpty()) {
122+
entity.setExamples(property.example());
123+
}
118124
}
119125
return entity;
120126
}
@@ -127,7 +133,10 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
127133
Property property = returnAnnotation.load();
128134
returnPropertyEntity.setName(property.name());
129135
returnPropertyEntity.setDescription(property.description());
130-
returnPropertyEntity.setExamples(Collections.singletonList(property.example()));
136+
// 只有当 example 不为空字符串时才设置
137+
if (!property.example().isEmpty()) {
138+
returnPropertyEntity.setExamples(property.example());
139+
}
131140
}
132141
notNull(methodDescription.getReturnType(), "The return type cannot be null.");
133142
JsonNode jsonNode = JacksonTypeParser.getParameterSchema(methodDescription.getReturnType());
@@ -142,6 +151,8 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
142151

143152
private static void setPropertyType(PropertyEntity returnPropertyEntity, JsonNode jsonNode) {
144153
returnPropertyEntity.setType(jsonNode.get("type").asText());
154+
returnPropertyEntity.setItems(null);
155+
returnPropertyEntity.setProperties(null);
145156
if (Objects.equals(returnPropertyEntity.getType(), "array")) {
146157
returnPropertyEntity.setItems(jsonNode.get("items"));
147158
}

framework/fel/java/maven-plugins/tool-maven-plugin/src/test/resources/weather-tools.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"type" : "object",
1414
"properties" : {
1515
"location" : {
16+
"defaultValue" : "Shanghai",
1617
"description" : "查询地点",
1718
"name" : "location",
1819
"type" : "string",

0 commit comments

Comments
 (0)