Skip to content

Commit 0c1b2b7

Browse files
[tool] Update plugin metadata to match standard json schema (#211)
1 parent f4602b6 commit 0c1b2b7

File tree

7 files changed

+122
-26
lines changed

7 files changed

+122
-26
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
import modelengine.fel.tool.info.entity.ReturnPropertyEntity;
1515
import modelengine.fel.tool.info.entity.SchemaEntity;
1616
import modelengine.fitframework.annotation.Property;
17-
import modelengine.fitframework.util.StringUtils;
1817

1918
import net.bytebuddy.description.annotation.AnnotationDescription;
2019
import net.bytebuddy.description.method.MethodDescription;
2120
import net.bytebuddy.description.method.ParameterDescription;
2221

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

24+
import java.util.ArrayList;
2525
import java.util.Arrays;
26+
import java.util.Collections;
2627
import java.util.LinkedHashMap;
2728
import java.util.LinkedList;
2829
import java.util.List;
@@ -78,9 +79,7 @@ private static Map<String, Object> getStringObjectMap(ReturnPropertyEntity retur
7879
if (returnPropertyEntity.getConvertor() != null) {
7980
returnProperty.put("convertor", returnPropertyEntity.getConvertor());
8081
}
81-
if (StringUtils.isNotBlank(returnPropertyEntity.getExample())) {
82-
returnProperty.put("example", returnPropertyEntity.getExample());
83-
}
82+
returnProperty.put("examples", returnPropertyEntity.getExamples());
8483
return returnProperty;
8584
}
8685

@@ -115,7 +114,7 @@ private static PropertyEntity parseProperty(ParameterDescription parameterDescri
115114
entity.setDescription(property.description());
116115
entity.setNeed(property.required());
117116
entity.setDefaultValue(property.defaultValue());
118-
entity.setExample(property.example());
117+
entity.setExamples(Collections.singletonList(property.example()));
119118
}
120119
return entity;
121120
}
@@ -128,7 +127,7 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
128127
Property property = returnAnnotation.load();
129128
returnPropertyEntity.setName(property.name());
130129
returnPropertyEntity.setDescription(property.description());
131-
returnPropertyEntity.setExample(property.example());
130+
returnPropertyEntity.setExamples(Collections.singletonList(property.example()));
132131
}
133132
notNull(methodDescription.getReturnType(), "The return type cannot be null.");
134133
JsonNode jsonNode = JacksonTypeParser.getParameterSchema(methodDescription.getReturnType());
@@ -153,6 +152,8 @@ private static void setPropertyType(PropertyEntity returnPropertyEntity, JsonNod
153152
List<String> requiredFields = new LinkedList<>();
154153
jsonNode.get("properties").fieldNames().forEachRemaining(requiredFields::add);
155154
returnPropertyEntity.setRequired(requiredFields);
155+
} else {
156+
returnPropertyEntity.setProperties(new ArrayList<>());
156157
}
157158
}
158159
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package modelengine.fel.maven.compile.parser.weather;
88

9+
import modelengine.fel.maven.compile.parser.weather.dto.RainPosition;
910
import modelengine.fel.tool.annotation.Group;
1011
import modelengine.fel.tool.annotation.ToolMethod;
1112
import modelengine.fitframework.annotation.Genericable;
@@ -31,8 +32,10 @@ public interface Rain {
3132
*/
3233
@ToolMethod(name = "rain_today", description = "该方法获取今天的下雨信息")
3334
@Genericable("genericable_weather_rain_today")
34-
String today(@Property(description = "查询地点", required = true) String location,
35-
@Property(description = "查询日期", required = true) Date date);
35+
String today(@Property(description = "查询地点", required = true, example = "Hangzhou") String location,
36+
@Property(description = "查询日期", required = true) Date date,
37+
@Property(description = "下雨的经纬度") RainPosition rainPosition,
38+
@Property(description = "其他信息") Object info);
3639

3740
/**
3841
* 获取明天下雨信息的结果。
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fel.maven.compile.parser.weather.dto;
8+
9+
/**
10+
* 添加测试用的工具的自定义结构体。
11+
*
12+
* @author 杭潇
13+
* @since 2025-07-21
14+
*/
15+
public class RainPosition {
16+
/**
17+
* 表示下雨位置的经度值的 {@link String}。
18+
*/
19+
String latitude;
20+
21+
/**
22+
* 表示下雨位置的纬度值的 {@link String}。
23+
*/
24+
String longitude;
25+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package modelengine.fel.maven.compile.parser.weather.impl;
88

9+
import modelengine.fel.maven.compile.parser.weather.dto.RainPosition;
910
import modelengine.fel.tool.annotation.Attribute;
1011
import modelengine.fel.tool.annotation.Group;
1112
import modelengine.fel.tool.annotation.ToolMethod;
@@ -34,7 +35,7 @@ public class CityARainImpl implements Rain {
3435
})
3536
@Property(description = "获取今日下雨信息的结果")
3637
@Override
37-
public String today(String location, Date date) {
38+
public String today(String location, Date date, RainPosition rainPosition, Object info) {
3839
return null;
3940
}
4041

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package modelengine.fel.maven.compile.parser.weather.impl;
88

9+
import modelengine.fel.maven.compile.parser.weather.dto.RainPosition;
910
import modelengine.fel.tool.annotation.Attribute;
1011
import modelengine.fel.tool.annotation.Group;
1112
import modelengine.fel.tool.annotation.ToolMethod;
@@ -30,7 +31,7 @@ public class CityBRainImpl implements Rain {
3031
@Attribute(key = "tags", value = "FIT"), @Attribute(key = "tags", value = "TEST")
3132
})
3233
@Override
33-
public String today(String location, Date date) {
34+
public String today(String location, Date date, RainPosition rainPosition, Object info) {
3435
return null;
3536
}
3637

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

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,47 @@
1313
"type" : "object",
1414
"properties" : {
1515
"location" : {
16-
"defaultValue" : "",
1716
"description" : "查询地点",
1817
"name" : "location",
1918
"type" : "string",
20-
"example" : ""
19+
"examples" : [ "Hangzhou" ],
20+
"default" : ""
2121
},
2222
"date" : {
23-
"defaultValue" : "",
2423
"description" : "查询日期",
2524
"name" : "date",
2625
"type" : "string",
27-
"example" : ""
26+
"examples" : [ "" ],
27+
"default" : ""
28+
},
29+
"rainPosition" : {
30+
"description" : "下雨的经纬度",
31+
"name" : "rainPosition",
32+
"type" : "object",
33+
"properties" : {
34+
"latitude" : {
35+
"type" : "string"
36+
},
37+
"longitude" : {
38+
"type" : "string"
39+
}
40+
},
41+
"examples" : [ "" ],
42+
"required" : [ "latitude", "longitude" ],
43+
"default" : ""
44+
},
45+
"info" : {
46+
"description" : "其他信息",
47+
"name" : "info",
48+
"type" : "object",
49+
"properties" : [ ],
50+
"examples" : [ "" ],
51+
"default" : ""
2852
}
2953
},
3054
"required" : [ "location", "date" ]
3155
},
32-
"order" : [ "location", "date" ],
56+
"order" : [ "location", "date", "rainPosition", "info" ],
3357
"return" : {
3458
"type" : "string",
3559
"convertor" : ""
@@ -85,16 +109,35 @@
85109
"date" : {
86110
"name" : "date",
87111
"type" : "string"
112+
},
113+
"rainPosition" : {
114+
"name" : "rainPosition",
115+
"type" : "object",
116+
"properties" : {
117+
"latitude" : {
118+
"type" : "string"
119+
},
120+
"longitude" : {
121+
"type" : "string"
122+
}
123+
},
124+
"required" : [ "latitude", "longitude" ]
125+
},
126+
"info" : {
127+
"name" : "info",
128+
"type" : "object",
129+
"properties" : [ ]
88130
}
89131
},
90132
"required" : [ ]
91133
},
92-
"order" : [ "location", "date" ],
134+
"order" : [ "location", "date", "rainPosition", "info" ],
93135
"return" : {
94136
"name" : "",
95137
"description" : "获取今日下雨信息的结果",
96138
"type" : "string",
97-
"convertor" : ""
139+
"convertor" : "",
140+
"examples" : [ "" ]
98141
}
99142
},
100143
"runnables" : {
@@ -131,7 +174,8 @@
131174
"name" : "",
132175
"description" : "获取明日下雨信息的结果",
133176
"type" : "string",
134-
"convertor" : ""
177+
"convertor" : "",
178+
"examples" : [ "" ]
135179
}
136180
},
137181
"runnables" : {
@@ -166,11 +210,29 @@
166210
"date" : {
167211
"name" : "date",
168212
"type" : "string"
213+
},
214+
"rainPosition" : {
215+
"name" : "rainPosition",
216+
"type" : "object",
217+
"properties" : {
218+
"latitude" : {
219+
"type" : "string"
220+
},
221+
"longitude" : {
222+
"type" : "string"
223+
}
224+
},
225+
"required" : [ "latitude", "longitude" ]
226+
},
227+
"info" : {
228+
"name" : "info",
229+
"type" : "object",
230+
"properties" : [ ]
169231
}
170232
},
171233
"required" : [ ]
172234
},
173-
"order" : [ "location", "date" ],
235+
"order" : [ "location", "date", "rainPosition", "info" ],
174236
"return" : {
175237
"type" : "string",
176238
"convertor" : ""

framework/fel/java/services/tool-info/src/main/java/modelengine/fel/tool/info/entity/PropertyEntity.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package modelengine.fel.tool.info.entity;
88

9+
import modelengine.fitframework.annotation.Property;
10+
911
import java.util.List;
1012

1113
/**
@@ -16,13 +18,14 @@
1618
* @since 2024-10-26
1719
*/
1820
public class PropertyEntity {
21+
@Property(name = "default")
1922
private String defaultValue;
2023
private String description;
2124
private String name;
2225
private String type;
2326
private Object items;
2427
private Object properties;
25-
private String example;
28+
private List<String> examples;
2629
private List<String> required;
2730
private transient boolean need;
2831

@@ -173,18 +176,18 @@ public void setProperties(Object properties) {
173176
/**
174177
* 获取参数的示例值。
175178
*
176-
* @return 表示参数的示例值的 {@link String}。
179+
* @return 表示参数的示例值的 {@link List}{@code <}{@link String}{@code >}。
177180
*/
178-
public String getExample() {
179-
return this.example;
181+
public List<String> getExamples() {
182+
return this.examples;
180183
}
181184

182185
/**
183186
* 设置参数的示例值。
184187
*
185-
* @param example 表示参数的示例值的 {@link String}。
188+
* @param examples 表示参数的示例值的 {@link List}{@code <}{@link String}{@code >}。
186189
*/
187-
public void setExample(String example) {
188-
this.example = example;
190+
public void setExamples(List<String> examples) {
191+
this.examples = examples;
189192
}
190193
}

0 commit comments

Comments
 (0)