Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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;
Expand Down Expand Up @@ -77,8 +78,8 @@ private static Map<String, Object> 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;
}
Expand All @@ -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);
}
}
Expand All @@ -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;
}
Expand All @@ -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());
Expand All @@ -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<String> requiredFields = new LinkedList<>();
jsonNode.get("properties").fieldNames().forEachRemaining(requiredFields::add);
returnPropertyEntity.setRequired(requiredFields);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -46,13 +44,11 @@
"properties" : {
"location" : {
"name" : "location",
"type" : "string",
"required" : false
"type" : "string"
},
"date" : {
"name" : "date",
"type" : "string",
"required" : false
"type" : "string"
}
},
"required" : [ ]
Expand Down Expand Up @@ -84,13 +80,11 @@
"properties" : {
"location" : {
"name" : "location",
"type" : "string",
"required" : false
"type" : "string"
},
"date" : {
"name" : "date",
"type" : "string",
"required" : false
"type" : "string"
}
},
"required" : [ ]
Expand All @@ -100,8 +94,7 @@
"name" : "",
"description" : "获取今日下雨信息的结果",
"type" : "string",
"convertor" : "",
"examples" : ""
"convertor" : ""
}
},
"runnables" : {
Expand All @@ -124,13 +117,11 @@
"properties" : {
"location" : {
"name" : "location",
"type" : "string",
"required" : false
"type" : "string"
},
"date" : {
"name" : "date",
"type" : "string",
"required" : false
"type" : "string"
}
},
"required" : [ ]
Expand All @@ -140,8 +131,7 @@
"name" : "",
"description" : "获取明日下雨信息的结果",
"type" : "string",
"convertor" : "",
"examples" : ""
"convertor" : ""
}
},
"runnables" : {
Expand Down Expand Up @@ -171,13 +161,11 @@
"properties" : {
"location" : {
"name" : "location",
"type" : "string",
"required" : false
"type" : "string"
},
"date" : {
"name" : "date",
"type" : "string",
"required" : false
"type" : "string"
}
},
"required" : [ ]
Expand Down Expand Up @@ -208,13 +196,11 @@
"properties" : {
"location" : {
"name" : "location",
"type" : "string",
"required" : false
"type" : "string"
},
"date" : {
"name" : "date",
"type" : "string",
"required" : false
"type" : "string"
}
},
"required" : [ ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package modelengine.fel.tool.info.entity;

import java.util.List;

/**
* 表示参数属性的实体类。
*
Expand All @@ -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<String> required;
private transient boolean need;

/**
* 获取参数的默认值。
Expand Down Expand Up @@ -59,22 +62,40 @@ public void setDescription(String description) {
this.description = description;
}

/**
* 获取对象类型的必填字段列表。
*
* @return 表示对象类型必填字段列表的 {@link List}{@code <}{@link String}{@code >}。
*/
public List<String> getRequired() {
return this.required;
}

/**
* 设置对象类型的必填字段列表。
*
* @param required 表示对象类型必填字段列表的 {@link List}{@code <}{@link String}{@code >}。
*/
public void setRequired(List<String> 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;
}

/**
Expand Down Expand Up @@ -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;
}
}