Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -79,7 +78,9 @@ private static Map<String, Object> getStringObjectMap(ReturnPropertyEntity retur
if (returnPropertyEntity.getConvertor() != null) {
returnProperty.put("convertor", returnPropertyEntity.getConvertor());
}
returnProperty.put("examples", returnPropertyEntity.getExamples());
if (returnPropertyEntity.getExamples() != null) {
returnProperty.put("examples", returnPropertyEntity.getExamples());
}
return returnProperty;
}

Expand Down Expand Up @@ -113,8 +114,14 @@ private static PropertyEntity parseProperty(ParameterDescription parameterDescri
Property property = paramAnnotation.load();
entity.setDescription(property.description());
entity.setNeed(property.required());
entity.setDefaultValue(property.defaultValue());
entity.setExamples(Collections.singletonList(property.example()));
String defaultValue = property.defaultValue();
if (defaultValue != null && !defaultValue.isEmpty()) {
entity.setDefaultValue(defaultValue);
}
String example = property.example();
if (example != null && !example.isEmpty()) {
entity.setExamples(Collections.singletonList(example));
}
}
return entity;
}
Expand All @@ -127,7 +134,10 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
Property property = returnAnnotation.load();
returnPropertyEntity.setName(property.name());
returnPropertyEntity.setDescription(property.description());
returnPropertyEntity.setExamples(Collections.singletonList(property.example()));
String example = property.example();
if (example != null && !example.isEmpty()) {
returnPropertyEntity.setExamples(Collections.singletonList(example));
}
}
notNull(methodDescription.getReturnType(), "The return type cannot be null.");
JsonNode jsonNode = JacksonTypeParser.getParameterSchema(methodDescription.getReturnType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public interface Rain {
*/
@ToolMethod(name = "rain_today", description = "该方法获取今天的下雨信息")
@Genericable("genericable_weather_rain_today")
String today(@Property(description = "查询地点", required = true, example = "Hangzhou") String location,
@Property(description = "查询日期", required = true) Date date,
String today(@Property(description = "查询地点", required = true, defaultValue = "Shanghai", example = "Hangzhou")
String location, @Property(description = "查询日期", required = true) Date date,
@Property(description = "下雨的经纬度") RainPosition rainPosition,
@Property(description = "其他信息") Object info);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
"name" : "location",
"type" : "string",
"examples" : [ "Hangzhou" ],
"default" : ""
"default" : "Shanghai"
},
"date" : {
"description" : "查询日期",
"name" : "date",
"type" : "string",
"examples" : [ "" ],
"default" : ""
"type" : "string"
},
"rainPosition" : {
"description" : "下雨的经纬度",
Expand All @@ -38,17 +36,13 @@
"type" : "string"
}
},
"examples" : [ "" ],
"required" : [ "latitude", "longitude" ],
"default" : ""
"required" : [ "latitude", "longitude" ]
},
"info" : {
"description" : "其他信息",
"name" : "info",
"type" : "object",
"properties" : { },
"examples" : [ "" ],
"default" : ""
"properties" : { }
}
},
"required" : [ "location", "date" ]
Expand Down Expand Up @@ -136,8 +130,7 @@
"name" : "",
"description" : "获取今日下雨信息的结果",
"type" : "string",
"convertor" : "",
"examples" : [ "" ]
"convertor" : ""
}
},
"runnables" : {
Expand Down Expand Up @@ -174,8 +167,7 @@
"name" : "",
"description" : "获取明日下雨信息的结果",
"type" : "string",
"convertor" : "",
"examples" : [ "" ]
"convertor" : ""
}
},
"runnables" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public Object parameterDefaultValue(String name) {
// TODO 需要考虑注解值的类型匹配与基础类型的默认值问题
Property annotation = parameter.getDeclaredAnnotation(Property.class);
if (annotation != null) {
return annotation.defaultValue();
String defaultValue = annotation.defaultValue();
if (defaultValue != null && !defaultValue.isEmpty()) {
return defaultValue;
}
}
return null;
}).orElse(null);
Expand Down