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 7eb640ac..6f375d85 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,6 +14,7 @@ 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; @@ -77,8 +78,8 @@ private static Map getStringObjectMap(ReturnPropertyEntity retur if (returnPropertyEntity.getConvertor() != null) { returnProperty.put("convertor", returnPropertyEntity.getConvertor()); } - if (returnPropertyEntity.getExamples() != null) { - returnProperty.put("examples", returnPropertyEntity.getExamples()); + if (StringUtils.isNotBlank(returnPropertyEntity.getExample())) { + returnProperty.put("example", returnPropertyEntity.getExample()); } return returnProperty; } @@ -92,7 +93,7 @@ private static ParameterEntity parseParameter(MethodDescription methodDescriptio String methodName = parameterDescription.getName(); PropertyEntity property = parseProperty(parameterDescription); properties.put(methodName, property); - if (property.isRequired()) { + if (property.isNeed()) { required.add(methodName); } } @@ -112,9 +113,9 @@ private static PropertyEntity parseProperty(ParameterDescription parameterDescri if (paramAnnotation != null) { Property property = paramAnnotation.load(); entity.setDescription(property.description()); - entity.setRequired(property.required()); + entity.setNeed(property.required()); entity.setDefaultValue(property.defaultValue()); - entity.setExamples(property.example()); + entity.setExample(property.example()); } return entity; } @@ -127,7 +128,7 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method Property property = returnAnnotation.load(); returnPropertyEntity.setName(property.name()); returnPropertyEntity.setDescription(property.description()); - returnPropertyEntity.setExamples(property.example()); + returnPropertyEntity.setExample(property.example()); } notNull(methodDescription.getReturnType(), "The return type cannot be null."); JsonNode jsonNode = JacksonTypeParser.getParameterSchema(methodDescription.getReturnType()); @@ -142,14 +143,16 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method private static void setPropertyType(PropertyEntity returnPropertyEntity, JsonNode jsonNode) { returnPropertyEntity.setType(jsonNode.get("type").asText()); - returnPropertyEntity.setItems(null); - returnPropertyEntity.setProperties(null); if (Objects.equals(returnPropertyEntity.getType(), "array")) { returnPropertyEntity.setItems(jsonNode.get("items")); } if (Objects.equals(returnPropertyEntity.getType(), "object")) { if (jsonNode.get("properties") != null) { returnPropertyEntity.setProperties(jsonNode.get("properties")); + // 为对象类型添加required数组,包含所有属性名 + List requiredFields = new LinkedList<>(); + jsonNode.get("properties").fieldNames().forEachRemaining(requiredFields::add); + returnPropertyEntity.setRequired(requiredFields); } } } 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 278ca967..6dd911d0 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 @@ -17,16 +17,14 @@ "description" : "查询地点", "name" : "location", "type" : "string", - "examples" : "", - "required" : true + "example" : "" }, "date" : { "defaultValue" : "", "description" : "查询日期", "name" : "date", "type" : "string", - "examples" : "", - "required" : true + "example" : "" } }, "required" : [ "location", "date" ] @@ -46,13 +44,11 @@ "properties" : { "location" : { "name" : "location", - "type" : "string", - "required" : false + "type" : "string" }, "date" : { "name" : "date", - "type" : "string", - "required" : false + "type" : "string" } }, "required" : [ ] @@ -84,13 +80,11 @@ "properties" : { "location" : { "name" : "location", - "type" : "string", - "required" : false + "type" : "string" }, "date" : { "name" : "date", - "type" : "string", - "required" : false + "type" : "string" } }, "required" : [ ] @@ -100,8 +94,7 @@ "name" : "", "description" : "获取今日下雨信息的结果", "type" : "string", - "convertor" : "", - "examples" : "" + "convertor" : "" } }, "runnables" : { @@ -124,13 +117,11 @@ "properties" : { "location" : { "name" : "location", - "type" : "string", - "required" : false + "type" : "string" }, "date" : { "name" : "date", - "type" : "string", - "required" : false + "type" : "string" } }, "required" : [ ] @@ -140,8 +131,7 @@ "name" : "", "description" : "获取明日下雨信息的结果", "type" : "string", - "convertor" : "", - "examples" : "" + "convertor" : "" } }, "runnables" : { @@ -171,13 +161,11 @@ "properties" : { "location" : { "name" : "location", - "type" : "string", - "required" : false + "type" : "string" }, "date" : { "name" : "date", - "type" : "string", - "required" : false + "type" : "string" } }, "required" : [ ] @@ -208,13 +196,11 @@ "properties" : { "location" : { "name" : "location", - "type" : "string", - "required" : false + "type" : "string" }, "date" : { "name" : "date", - "type" : "string", - "required" : false + "type" : "string" } }, "required" : [ ] 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 4a1b3a1f..5c1d66a3 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 java.util.List; + /** * 表示参数属性的实体类。 * @@ -20,8 +22,9 @@ public class PropertyEntity { private String type; private Object items; private Object properties; - private String examples; - private boolean required; + private String example; + private List required; + private transient boolean need; /** * 获取参数的默认值。 @@ -59,22 +62,40 @@ public void setDescription(String description) { this.description = description; } + /** + * 获取对象类型的必填字段列表。 + * + * @return 表示对象类型必填字段列表的 {@link List}{@code <}{@link String}{@code >}。 + */ + public List getRequired() { + return this.required; + } + + /** + * 设置对象类型的必填字段列表。 + * + * @param required 表示对象类型必填字段列表的 {@link List}{@code <}{@link String}{@code >}。 + */ + public void setRequired(List required) { + this.required = required; + } + /** * 获取参数是否是必需的标志。 * * @return 如果参数是必需的,则返回 {@code true},否则返回 {@code false}。 */ - public boolean isRequired() { - return this.required; + public boolean isNeed() { + return need; } /** * 设置参数是否是必需的标志。 * - * @param required 表示参数是否是必需的 {@link boolean}。 + * @param need 表示参数是否是必需的 {@link boolean}。 */ - public void setRequired(boolean required) { - this.required = required; + public void setNeed(boolean need) { + this.need = need; } /** @@ -154,16 +175,16 @@ public void setProperties(Object properties) { * * @return 表示参数的示例值的 {@link String}。 */ - public String getExamples() { - return this.examples; + public String getExample() { + return this.example; } /** * 设置参数的示例值。 * - * @param examples 表示参数的示例值的 {@link String}。 + * @param example 表示参数的示例值的 {@link String}。 */ - public void setExamples(String examples) { - this.examples = examples; + public void setExample(String example) { + this.example = example; } }