Search in sources :

Example 6 with ApiFolderObject

use of com.terran4j.commons.api2doc.domain.ApiFolderObject in project commons by terran4j.

the class ApiMetaService method toClassMetaList.

public List<ClassMeta> toClassMetaList() {
    List<ClassMeta> classes = new ArrayList<>();
    List<ApiFolderObject> folderList = api2DocService.getFolders();
    if (folderList == null || folderList.isEmpty()) {
        return classes;
    }
    for (ApiFolderObject folder : folderList) {
        ClassMeta classMeta = toClassMeta(folder);
        classes.add(classMeta);
    }
    return classes;
}
Also used : ApiFolderObject(com.terran4j.commons.api2doc.domain.ApiFolderObject) ArrayList(java.util.ArrayList)

Example 7 with ApiFolderObject

use of com.terran4j.commons.api2doc.domain.ApiFolderObject in project commons by terran4j.

the class Api2DocCollectorTest method testToApiFolder.

@Test
public void testToApiFolder() throws Exception {
    log.info("testToApiFolder");
    Api2DocCollector collector = new Api2DocCollector();
    ApiFolderObject folder = collector.toApiFolder(new UserController(), "userController");
    Assert.assertNotNull(folder);
    Assert.assertEquals(4, folder.getDocs().size());
    // 按 order 及 方法中排序。
    Assert.assertEquals("delete", folder.getDocs().get(0).getId());
    Assert.assertEquals("getUser", folder.getDocs().get(1).getId());
    Assert.assertEquals("getUsers", folder.getDocs().get(2).getId());
    Assert.assertEquals("insert", folder.getDocs().get(3).getId());
}
Also used : Api2DocCollector(com.terran4j.commons.api2doc.impl.Api2DocCollector) ApiFolderObject(com.terran4j.commons.api2doc.domain.ApiFolderObject) Test(org.junit.Test)

Example 8 with ApiFolderObject

use of com.terran4j.commons.api2doc.domain.ApiFolderObject in project commons by terran4j.

the class Api2DocUtilsTest method testToURL.

@Test
public void testToURL() throws Exception {
    log.info("testToURL");
    Api2DocCollector collector = new Api2DocCollector();
    ApiFolderObject folder = collector.toApiFolder(new Api2DocUtilsTestController(), "userController");
    ApiDocObject doc = folder.getDoc("getUser");
    String url = Api2DocUtils.toURL(doc, serverURL);
    Assert.assertEquals("http://localhost:8080/api/v1/user/123", url);
    doc = folder.getDoc("getUser2");
    url = Api2DocUtils.toURL(doc, serverURL);
    Assert.assertEquals("http://localhost:8080/api/v1/user2/0", url);
    doc = folder.getDoc("getUsers");
    url = Api2DocUtils.toURL(doc, serverURL);
    Assert.assertEquals("http://localhost:8080/api/v1/group/3/users?" + "age=30&city=%E5%8C%97%E4%BA%AC", url);
}
Also used : Api2DocCollector(com.terran4j.commons.api2doc.impl.Api2DocCollector) ApiFolderObject(com.terran4j.commons.api2doc.domain.ApiFolderObject) ApiDocObject(com.terran4j.commons.api2doc.domain.ApiDocObject) Test(org.junit.Test)

Example 9 with ApiFolderObject

use of com.terran4j.commons.api2doc.domain.ApiFolderObject in project commons by terran4j.

the class CurlBuilderTest method loadDoc.

private ApiDocObject loadDoc(String methodName) throws BusinessException {
    ApiFolderObject folder = collector.toApiFolder(new CurlBuilderTest(), "curlBuilderTest");
    ApiDocObject doc = folder.getDoc(methodName);
    Assert.assertNotNull(doc);
    return doc;
}
Also used : ApiFolderObject(com.terran4j.commons.api2doc.domain.ApiFolderObject) ApiDocObject(com.terran4j.commons.api2doc.domain.ApiDocObject)

Example 10 with ApiFolderObject

use of com.terran4j.commons.api2doc.domain.ApiFolderObject in project commons by terran4j.

the class ParseApiCommentOnSeeClass method testParseApiCommentOnSeeClass.

@Test
public void testParseApiCommentOnSeeClass() throws Exception {
    log.info("testParseApiCommentOnSeeClass");
    Api2DocCollector collector = new Api2DocCollector();
    ApiFolderObject folder = collector.toApiFolder(new ParseApiCommentOnSeeClass.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());
}
Also used : Api2DocCollector(com.terran4j.commons.api2doc.impl.Api2DocCollector) ApiParamObject(com.terran4j.commons.api2doc.domain.ApiParamObject) ApiFolderObject(com.terran4j.commons.api2doc.domain.ApiFolderObject) ApiDocObject(com.terran4j.commons.api2doc.domain.ApiDocObject) ApiResultObject(com.terran4j.commons.api2doc.domain.ApiResultObject) Test(org.junit.Test)

Aggregations

ApiFolderObject (com.terran4j.commons.api2doc.domain.ApiFolderObject)10 ApiDocObject (com.terran4j.commons.api2doc.domain.ApiDocObject)6 Api2DocCollector (com.terran4j.commons.api2doc.impl.Api2DocCollector)5 Test (org.junit.Test)5 ApiParamObject (com.terran4j.commons.api2doc.domain.ApiParamObject)3 ApiResultObject (com.terran4j.commons.api2doc.domain.ApiResultObject)2 ArrayList (java.util.ArrayList)2 MenuData (com.terran4j.commons.api2doc.controller.MenuData)1