use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.
the class ApiResultObjectTest method testParseResultTypeWithNotOrder.
@Test
public void testParseResultTypeWithNotOrder() throws Exception {
log.info("testParseResultTypeWithNotOrder");
Method method = ReflectionUtils.findMethod(getClass(), "getNotOrderBean");
Assert.assertNotNull(method);
ApiResultObject object = ApiResultObject.parseResultType(method, null);
Assert.assertNotNull(object);
Assert.assertEquals(4, object.getChildren().size());
Assert.assertEquals("abc", object.getChildren().get(0).getId());
Assert.assertEquals("abd", object.getChildren().get(1).getId());
Assert.assertEquals("b1", object.getChildren().get(2).getId());
Assert.assertEquals("b2", object.getChildren().get(3).getId());
}
use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.
the class ApiResultObjectTest method testParseResultType.
@Test
public void testParseResultType() throws Exception {
log.info("testParseResultType");
Method method = ReflectionUtils.findMethod(getClass(), "getUsers");
Assert.assertNotNull(method);
KeyedList<String, ApiResultObject> totalResults = new KeyedList<>();
ApiResultObject object = ApiResultObject.parseResultType(method, totalResults);
Assert.assertNotNull(object);
Assert.assertEquals(1, totalResults.size());
Assert.assertTrue(object == totalResults.get(0));
Assert.assertTrue(ApiDataType.ARRAY == object.getDataType());
Assert.assertTrue(User.class == object.getSourceType());
}
use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.
the class ApiResultObjectTest method testParseResultTypeWithIgnore.
@Test
public void testParseResultTypeWithIgnore() throws Exception {
log.info("testParseResultTypeWithIgnore");
Method method = ReflectionUtils.findMethod(getClass(), "getUsers");
Assert.assertNotNull(method);
KeyedList<String, ApiResultObject> totalResults = new KeyedList<>();
ApiResultObject object = ApiResultObject.parseResultType(method, totalResults);
Assert.assertNotNull(object);
Assert.assertNull(object.getChild("deleted"));
}
use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.
the class ParseApiCommentOnSeeClassLoop method testParseApiCommentOnSeeClassLoop.
@Test
public void testParseApiCommentOnSeeClassLoop() throws Exception {
log.info("testParseApiCommentOnSeeClass");
Api2DocCollector collector = new Api2DocCollector();
ApiFolderObject folder = collector.toApiFolder(new ParseApiCommentOnSeeClassLoop.MyController(), "myController");
ApiDocObject doc = folder.getDoc("updateUser");
List<ApiParamObject> params = doc.getParams();
Assert.assertEquals("用户id", params.get(0).getComment().toString());
Assert.assertEquals("123", params.get(0).getSample().toString());
Assert.assertEquals("用户名称", params.get(1).getComment().toString());
Assert.assertEquals("neo", params.get(1).getSample().toString());
ApiResultObject user = doc.getResults().get(0);
ApiResultObject userId = user.getChildren().get(0);
Assert.assertEquals("id", userId.getId());
Assert.assertEquals("用户id", userId.getComment().getValue());
Assert.assertEquals("123", userId.getSample().getValue());
ApiResultObject userName = user.getChildren().get(1);
Assert.assertEquals("name", userName.getId());
Assert.assertEquals("用户名称", userName.getComment().getValue());
Assert.assertEquals("neo", userName.getSample().getValue());
}
use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.
the class JavaBeanCodeWriter method getModel.
public //
Map<String, Object> getModel(//
ApiResultObject result, //
String className, CodeConfig config) {
Map<String, Object> model = new HashedMap<>();
model.put("class", className);
if (config == null) {
config = new CodeConfig();
}
model.put("config", config);
// java 类上的注释。
String comment = result.getComment().javadoc(0);
if (StringUtils.hasText(comment)) {
model.put("comment", comment);
}
Set<String> imports = new HashSet<>();
model.put("imports", imports);
List<FieldInfo> fields = new ArrayList<FieldInfo>();
List<ApiResultObject> children = result.getChildren();
for (ApiResultObject child : children) {
FieldInfo field = new FieldInfo();
String name = child.getId();
field.setName(name);
String type = toTypeName(child);
field.setType(type);
String fieldComment = child.getComment().javadoc(1);
if (StringUtils.hasText(fieldComment)) {
field.setComment(fieldComment);
}
// Date 自动转成 Long 类型了。
Class<?> sourceType = getSourceType(child);
CodeUtils.addImport(sourceType, imports);
boolean isBooleanClass = (child.getDataType() == ApiDataType.BOOLEAN);
String getMethod = toGetMethodName(isBooleanClass, name);
field.setGetMethod(getMethod);
String setMethod = toSetMethodName(name);
field.setSetMethod(setMethod);
fields.add(field);
}
model.put("fields", fields);
return model;
}
Aggregations