Skip to content

Commit 7593d26

Browse files
[maven-tool] 对于默认的参数值,若为空,不添加该值
1 parent 80f6851 commit 7593d26

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

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

24-
import java.util.ArrayList;
2524
import java.util.Arrays;
2625
import java.util.Collections;
2726
import java.util.LinkedHashMap;
@@ -79,7 +78,9 @@ private static Map<String, Object> getStringObjectMap(ReturnPropertyEntity retur
7978
if (returnPropertyEntity.getConvertor() != null) {
8079
returnProperty.put("convertor", returnPropertyEntity.getConvertor());
8180
}
82-
returnProperty.put("examples", returnPropertyEntity.getExamples());
81+
if (returnPropertyEntity.getExamples() != null) {
82+
returnProperty.put("examples", returnPropertyEntity.getExamples());
83+
}
8384
return returnProperty;
8485
}
8586

@@ -113,8 +114,14 @@ private static PropertyEntity parseProperty(ParameterDescription parameterDescri
113114
Property property = paramAnnotation.load();
114115
entity.setDescription(property.description());
115116
entity.setNeed(property.required());
116-
entity.setDefaultValue(property.defaultValue());
117-
entity.setExamples(Collections.singletonList(property.example()));
117+
String defaultValue = property.defaultValue();
118+
if (defaultValue != null && !defaultValue.isEmpty()) {
119+
entity.setDefaultValue(defaultValue);
120+
}
121+
String example = property.example();
122+
if (example != null && !example.isEmpty()) {
123+
entity.setExamples(Collections.singletonList(example));
124+
}
118125
}
119126
return entity;
120127
}
@@ -127,7 +134,10 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
127134
Property property = returnAnnotation.load();
128135
returnPropertyEntity.setName(property.name());
129136
returnPropertyEntity.setDescription(property.description());
130-
returnPropertyEntity.setExamples(Collections.singletonList(property.example()));
137+
String example = property.example();
138+
if (example != null && !example.isEmpty()) {
139+
returnPropertyEntity.setExamples(Collections.singletonList(example));
140+
}
131141
}
132142
notNull(methodDescription.getReturnType(), "The return type cannot be null.");
133143
JsonNode jsonNode = JacksonTypeParser.getParameterSchema(methodDescription.getReturnType());

framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/Rain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public interface Rain {
3232
*/
3333
@ToolMethod(name = "rain_today", description = "该方法获取今天的下雨信息")
3434
@Genericable("genericable_weather_rain_today")
35-
String today(@Property(description = "查询地点", required = true, example = "Hangzhou") String location,
36-
@Property(description = "查询日期", required = true) Date date,
35+
String today(@Property(description = "查询地点", required = true, defaultValue = "Shanghai", example = "Hangzhou")
36+
String location, @Property(description = "查询日期", required = true) Date date,
3737
@Property(description = "下雨的经纬度") RainPosition rainPosition,
3838
@Property(description = "其他信息") Object info);
3939

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
"name" : "location",
1818
"type" : "string",
1919
"examples" : [ "Hangzhou" ],
20-
"default" : ""
20+
"default" : "Shanghai"
2121
},
2222
"date" : {
2323
"description" : "查询日期",
2424
"name" : "date",
25-
"type" : "string",
26-
"examples" : [ "" ],
27-
"default" : ""
25+
"type" : "string"
2826
},
2927
"rainPosition" : {
3028
"description" : "下雨的经纬度",
@@ -38,17 +36,13 @@
3836
"type" : "string"
3937
}
4038
},
41-
"examples" : [ "" ],
42-
"required" : [ "latitude", "longitude" ],
43-
"default" : ""
39+
"required" : [ "latitude", "longitude" ]
4440
},
4541
"info" : {
4642
"description" : "其他信息",
4743
"name" : "info",
4844
"type" : "object",
49-
"properties" : { },
50-
"examples" : [ "" ],
51-
"default" : ""
45+
"properties" : { }
5246
}
5347
},
5448
"required" : [ "location", "date" ]
@@ -136,8 +130,7 @@
136130
"name" : "",
137131
"description" : "获取今日下雨信息的结果",
138132
"type" : "string",
139-
"convertor" : "",
140-
"examples" : [ "" ]
133+
"convertor" : ""
141134
}
142135
},
143136
"runnables" : {
@@ -174,8 +167,7 @@
174167
"name" : "",
175168
"description" : "获取明日下雨信息的结果",
176169
"type" : "string",
177-
"convertor" : "",
178-
"examples" : [ "" ]
170+
"convertor" : ""
179171
}
180172
},
181173
"runnables" : {

framework/fel/java/services/tool-service/src/main/java/modelengine/fel/tool/support/MethodToolMetadata.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public Object parameterDefaultValue(String name) {
6767
// TODO 需要考虑注解值的类型匹配与基础类型的默认值问题
6868
Property annotation = parameter.getDeclaredAnnotation(Property.class);
6969
if (annotation != null) {
70-
return annotation.defaultValue();
70+
String defaultValue = annotation.defaultValue();
71+
if (defaultValue != null && !defaultValue.isEmpty()) {
72+
return defaultValue;
73+
}
7174
}
7275
return null;
7376
}).orElse(null);

0 commit comments

Comments
 (0)