2121
2222import static modelengine .fitframework .inspection .Validation .notNull ;
2323
24- import java .util .ArrayList ;
2524import java .util .Arrays ;
26- import java .util .Collections ;
2725import java .util .LinkedHashMap ;
2826import java .util .LinkedList ;
2927import java .util .List ;
@@ -79,7 +77,9 @@ private static Map<String, Object> getStringObjectMap(ReturnPropertyEntity retur
7977 if (returnPropertyEntity .getConvertor () != null ) {
8078 returnProperty .put ("convertor" , returnPropertyEntity .getConvertor ());
8179 }
82- returnProperty .put ("examples" , returnPropertyEntity .getExamples ());
80+ if (returnPropertyEntity .getExamples () != null ) {
81+ returnProperty .put ("examples" , returnPropertyEntity .getExamples ());
82+ }
8383 return returnProperty ;
8484 }
8585
@@ -92,7 +92,7 @@ private static ParameterEntity parseParameter(MethodDescription methodDescriptio
9292 String methodName = parameterDescription .getName ();
9393 PropertyEntity property = parseProperty (parameterDescription );
9494 properties .put (methodName , property );
95- if (property .isNeed ()) {
95+ if (property .isRequired ()) {
9696 required .add (methodName );
9797 }
9898 }
@@ -112,9 +112,15 @@ private static PropertyEntity parseProperty(ParameterDescription parameterDescri
112112 if (paramAnnotation != null ) {
113113 Property property = paramAnnotation .load ();
114114 entity .setDescription (property .description ());
115- entity .setNeed (property .required ());
116- entity .setDefaultValue (property .defaultValue ());
117- entity .setExamples (Collections .singletonList (property .example ()));
115+ entity .setRequired (property .required ());
116+ // 只有当 defaultValue 不为空字符串时才设置
117+ if (!property .defaultValue ().isEmpty ()) {
118+ entity .setDefaultValue (property .defaultValue ());
119+ }
120+ // 只有当 example 不为空字符串时才设置
121+ if (!property .example ().isEmpty ()) {
122+ entity .setExamples (property .example ());
123+ }
118124 }
119125 return entity ;
120126 }
@@ -127,7 +133,10 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
127133 Property property = returnAnnotation .load ();
128134 returnPropertyEntity .setName (property .name ());
129135 returnPropertyEntity .setDescription (property .description ());
130- returnPropertyEntity .setExamples (Collections .singletonList (property .example ()));
136+ // 只有当 example 不为空字符串时才设置
137+ if (!property .example ().isEmpty ()) {
138+ returnPropertyEntity .setExamples (property .example ());
139+ }
131140 }
132141 notNull (methodDescription .getReturnType (), "The return type cannot be null." );
133142 JsonNode jsonNode = JacksonTypeParser .getParameterSchema (methodDescription .getReturnType ());
@@ -142,6 +151,8 @@ private static ReturnPropertyEntity parseReturnProperty(MethodDescription method
142151
143152 private static void setPropertyType (PropertyEntity returnPropertyEntity , JsonNode jsonNode ) {
144153 returnPropertyEntity .setType (jsonNode .get ("type" ).asText ());
154+ returnPropertyEntity .setItems (null );
155+ returnPropertyEntity .setProperties (null );
145156 if (Objects .equals (returnPropertyEntity .getType (), "array" )) {
146157 returnPropertyEntity .setItems (jsonNode .get ("items" ));
147158 }
0 commit comments