From 358f145fa17117268b21289de1f4ed6bdd7b7624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=AD=E6=BD=87?= <1576730710@qq.com> Date: Mon, 21 Jul 2025 11:34:14 +0800 Subject: [PATCH] [tool] Update plugin metadata to match standard json schema --- .../complie/parser/ByteBuddySchemaParser.java | 13 +-- .../maven/compile/parser/weather/Rain.java | 7 +- .../parser/weather/dto/RainPosition.java | 25 ++++++ .../parser/weather/impl/CityARainImpl.java | 3 +- .../parser/weather/impl/CityBRainImpl.java | 3 +- .../src/test/resources/weather-tools.json | 80 ++++++++++++++++--- .../fel/tool/info/entity/PropertyEntity.java | 17 ++-- 7 files changed, 122 insertions(+), 26 deletions(-) create mode 100644 framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/dto/RainPosition.java diff --git a/framework/fel/java/maven-plugins/tool-maven-plugin/src/main/java/modelengine/fel/maven/complie/parser/ByteBuddySchemaParser.java b/framework/fel/java/maven-plugins/tool-maven-plugin/src/main/java/modelengine/fel/maven/complie/parser/ByteBuddySchemaParser.java index 6f375d85..32fa2925 100644 --- a/framework/fel/java/maven-plugins/tool-maven-plugin/src/main/java/modelengine/fel/maven/complie/parser/ByteBuddySchemaParser.java +++ b/framework/fel/java/maven-plugins/tool-maven-plugin/src/main/java/modelengine/fel/maven/complie/parser/ByteBuddySchemaParser.java @@ -14,7 +14,6 @@ import modelengine.fel.tool.info.entity.ReturnPropertyEntity; import modelengine.fel.tool.info.entity.SchemaEntity; import modelengine.fitframework.annotation.Property; -import modelengine.fitframework.util.StringUtils; import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.method.MethodDescription; @@ -22,7 +21,9 @@ import static modelengine.fitframework.inspection.Validation.notNull; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -78,9 +79,7 @@ private static Map getStringObjectMap(ReturnPropertyEntity retur if (returnPropertyEntity.getConvertor() != null) { returnProperty.put("convertor", returnPropertyEntity.getConvertor()); } - if (StringUtils.isNotBlank(returnPropertyEntity.getExample())) { - returnProperty.put("example", returnPropertyEntity.getExample()); - } + returnProperty.put("examples", returnPropertyEntity.getExamples()); return returnProperty; } @@ -115,7 +114,7 @@ private static PropertyEntity parseProperty(ParameterDescription parameterDescri entity.setDescription(property.description()); entity.setNeed(property.required()); entity.setDefaultValue(property.defaultValue()); - entity.setExample(property.example()); + entity.setExamples(Collections.singletonList(property.example())); } return entity; } @@ -128,7 +127,7 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method Property property = returnAnnotation.load(); returnPropertyEntity.setName(property.name()); returnPropertyEntity.setDescription(property.description()); - returnPropertyEntity.setExample(property.example()); + returnPropertyEntity.setExamples(Collections.singletonList(property.example())); } notNull(methodDescription.getReturnType(), "The return type cannot be null."); JsonNode jsonNode = JacksonTypeParser.getParameterSchema(methodDescription.getReturnType()); @@ -153,6 +152,8 @@ private static void setPropertyType(PropertyEntity returnPropertyEntity, JsonNod List requiredFields = new LinkedList<>(); jsonNode.get("properties").fieldNames().forEachRemaining(requiredFields::add); returnPropertyEntity.setRequired(requiredFields); + } else { + returnPropertyEntity.setProperties(new ArrayList<>()); } } } diff --git a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/Rain.java b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/Rain.java index fdd1f70b..eb3a728d 100644 --- a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/Rain.java +++ b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/Rain.java @@ -6,6 +6,7 @@ package modelengine.fel.maven.compile.parser.weather; +import modelengine.fel.maven.compile.parser.weather.dto.RainPosition; import modelengine.fel.tool.annotation.Group; import modelengine.fel.tool.annotation.ToolMethod; import modelengine.fitframework.annotation.Genericable; @@ -31,8 +32,10 @@ public interface Rain { */ @ToolMethod(name = "rain_today", description = "该方法获取今天的下雨信息") @Genericable("genericable_weather_rain_today") - String today(@Property(description = "查询地点", required = true) String location, - @Property(description = "查询日期", required = true) Date date); + String today(@Property(description = "查询地点", required = true, example = "Hangzhou") String location, + @Property(description = "查询日期", required = true) Date date, + @Property(description = "下雨的经纬度") RainPosition rainPosition, + @Property(description = "其他信息") Object info); /** * 获取明天下雨信息的结果。 diff --git a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/dto/RainPosition.java b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/dto/RainPosition.java new file mode 100644 index 00000000..f9e3cdaa --- /dev/null +++ b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/dto/RainPosition.java @@ -0,0 +1,25 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * This file is a part of the ModelEngine Project. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +package modelengine.fel.maven.compile.parser.weather.dto; + +/** + * 添加测试用的工具的自定义结构体。 + * + * @author 杭潇 + * @since 2025-07-21 + */ +public class RainPosition { + /** + * 表示下雨位置的经度值的 {@link String}。 + */ + String latitude; + + /** + * 表示下雨位置的纬度值的 {@link String}。 + */ + String longitude; +} \ No newline at end of file diff --git a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/impl/CityARainImpl.java b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/impl/CityARainImpl.java index ca9fffcf..8979d3aa 100644 --- a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/impl/CityARainImpl.java +++ b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/impl/CityARainImpl.java @@ -6,6 +6,7 @@ package modelengine.fel.maven.compile.parser.weather.impl; +import modelengine.fel.maven.compile.parser.weather.dto.RainPosition; import modelengine.fel.tool.annotation.Attribute; import modelengine.fel.tool.annotation.Group; import modelengine.fel.tool.annotation.ToolMethod; @@ -34,7 +35,7 @@ public class CityARainImpl implements Rain { }) @Property(description = "获取今日下雨信息的结果") @Override - public String today(String location, Date date) { + public String today(String location, Date date, RainPosition rainPosition, Object info) { return null; } diff --git a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/impl/CityBRainImpl.java b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/impl/CityBRainImpl.java index ca94a7e0..3a036a06 100644 --- a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/impl/CityBRainImpl.java +++ b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/java/modelengine/fel/maven/compile/parser/weather/impl/CityBRainImpl.java @@ -6,6 +6,7 @@ package modelengine.fel.maven.compile.parser.weather.impl; +import modelengine.fel.maven.compile.parser.weather.dto.RainPosition; import modelengine.fel.tool.annotation.Attribute; import modelengine.fel.tool.annotation.Group; import modelengine.fel.tool.annotation.ToolMethod; @@ -30,7 +31,7 @@ public class CityBRainImpl implements Rain { @Attribute(key = "tags", value = "FIT"), @Attribute(key = "tags", value = "TEST") }) @Override - public String today(String location, Date date) { + public String today(String location, Date date, RainPosition rainPosition, Object info) { return null; } diff --git a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/resources/weather-tools.json b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/resources/weather-tools.json index 6dd911d0..868e1495 100644 --- a/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/resources/weather-tools.json +++ b/framework/fel/java/maven-plugins/tool-maven-plugin/src/test/resources/weather-tools.json @@ -13,23 +13,47 @@ "type" : "object", "properties" : { "location" : { - "defaultValue" : "", "description" : "查询地点", "name" : "location", "type" : "string", - "example" : "" + "examples" : [ "Hangzhou" ], + "default" : "" }, "date" : { - "defaultValue" : "", "description" : "查询日期", "name" : "date", "type" : "string", - "example" : "" + "examples" : [ "" ], + "default" : "" + }, + "rainPosition" : { + "description" : "下雨的经纬度", + "name" : "rainPosition", + "type" : "object", + "properties" : { + "latitude" : { + "type" : "string" + }, + "longitude" : { + "type" : "string" + } + }, + "examples" : [ "" ], + "required" : [ "latitude", "longitude" ], + "default" : "" + }, + "info" : { + "description" : "其他信息", + "name" : "info", + "type" : "object", + "properties" : [ ], + "examples" : [ "" ], + "default" : "" } }, "required" : [ "location", "date" ] }, - "order" : [ "location", "date" ], + "order" : [ "location", "date", "rainPosition", "info" ], "return" : { "type" : "string", "convertor" : "" @@ -85,16 +109,35 @@ "date" : { "name" : "date", "type" : "string" + }, + "rainPosition" : { + "name" : "rainPosition", + "type" : "object", + "properties" : { + "latitude" : { + "type" : "string" + }, + "longitude" : { + "type" : "string" + } + }, + "required" : [ "latitude", "longitude" ] + }, + "info" : { + "name" : "info", + "type" : "object", + "properties" : [ ] } }, "required" : [ ] }, - "order" : [ "location", "date" ], + "order" : [ "location", "date", "rainPosition", "info" ], "return" : { "name" : "", "description" : "获取今日下雨信息的结果", "type" : "string", - "convertor" : "" + "convertor" : "", + "examples" : [ "" ] } }, "runnables" : { @@ -131,7 +174,8 @@ "name" : "", "description" : "获取明日下雨信息的结果", "type" : "string", - "convertor" : "" + "convertor" : "", + "examples" : [ "" ] } }, "runnables" : { @@ -166,11 +210,29 @@ "date" : { "name" : "date", "type" : "string" + }, + "rainPosition" : { + "name" : "rainPosition", + "type" : "object", + "properties" : { + "latitude" : { + "type" : "string" + }, + "longitude" : { + "type" : "string" + } + }, + "required" : [ "latitude", "longitude" ] + }, + "info" : { + "name" : "info", + "type" : "object", + "properties" : [ ] } }, "required" : [ ] }, - "order" : [ "location", "date" ], + "order" : [ "location", "date", "rainPosition", "info" ], "return" : { "type" : "string", "convertor" : "" diff --git a/framework/fel/java/services/tool-info/src/main/java/modelengine/fel/tool/info/entity/PropertyEntity.java b/framework/fel/java/services/tool-info/src/main/java/modelengine/fel/tool/info/entity/PropertyEntity.java index 5c1d66a3..8f093744 100644 --- a/framework/fel/java/services/tool-info/src/main/java/modelengine/fel/tool/info/entity/PropertyEntity.java +++ b/framework/fel/java/services/tool-info/src/main/java/modelengine/fel/tool/info/entity/PropertyEntity.java @@ -6,6 +6,8 @@ package modelengine.fel.tool.info.entity; +import modelengine.fitframework.annotation.Property; + import java.util.List; /** @@ -16,13 +18,14 @@ * @since 2024-10-26 */ public class PropertyEntity { + @Property(name = "default") private String defaultValue; private String description; private String name; private String type; private Object items; private Object properties; - private String example; + private List examples; private List required; private transient boolean need; @@ -173,18 +176,18 @@ public void setProperties(Object properties) { /** * 获取参数的示例值。 * - * @return 表示参数的示例值的 {@link String}。 + * @return 表示参数的示例值的 {@link List}{@code <}{@link String}{@code >}。 */ - public String getExample() { - return this.example; + public List getExamples() { + return this.examples; } /** * 设置参数的示例值。 * - * @param example 表示参数的示例值的 {@link String}。 + * @param examples 表示参数的示例值的 {@link List}{@code <}{@link String}{@code >}。 */ - public void setExample(String example) { - this.example = example; + public void setExamples(List examples) { + this.examples = examples; } }