ApiDocGenerator extends AbstractGenerator { @Override public void generateApi(ApiInfo apiInfo) throws Exception { apiInfo.getMethodInfos().forEach(r -> generateApiMethod(apiInfo, r)); } ApiDocGenerator(); ApiDocProject getApiDocProject(); void setApiDocProject(ApiDocProject apiDocProject); @Override void generateTool(); @Override void generateApi(ApiInfo apiInfo); @Override void generateMessage(MessageInfo messageInfo); boolean isAmd(); void setAmd(boolean amd); static final String API_PROJECT; static final String API_DATA; static final String JSON_SUFFIX; static final String JS_SUFFIX; }
@Test public void generateApi() throws Exception { Context context = new Context(); String apiCode = readCode("api/DocApiController.java"); String testFormCode = readCode("api/form/TestForm.java"); String testObjectCode = readCode("api/model/TestObject.java"); String userCode = readCode("api/model/User.java"); Analyse analyse = createAnalyse(); ApiInfo api = (ApiInfo) analyse.analyse(apiCode, "api"); assertNotNull(api); context.add(api); ModuleInfo testFormModule = analyse.analyse(testFormCode, "api.form"); ModuleInfo testObjectModule = analyse.analyse(testObjectCode, "api.model"); ModuleInfo userModule = analyse.analyse(userCode, "api.model"); assertNotNull(testFormModule); context.add(testFormModule); assertNotNull(testObjectModule); context.add(testObjectModule); assertNotNull(userModule); context.add(userModule); ApiDocGenerator apiDocGenerator = new ApiDocGenerator(); apiDocGenerator.setAmd(true); apiDocGenerator.generate(context); List<ApiDocApi> apis = apiDocGenerator.getApis(); assertEquals(apis.size(), 11); ApiDocApi loginApiDoc = apis.stream().filter(r -> r.getName().equals("login")).findAny().get(); assertEquals(loginApiDoc.getTitle(), "后台管理登录接口"); List<ApiDocApi.Field> loginResultFields = getResultFields(loginApiDoc); ApiDocApi.Field dataField = loginResultFields.stream().filter(getRegDates("data")).findAny().get(); assertNotNull(dataField); assertEquals(dataField.getType(), "String"); assertEquals(dataField.getDescription(), "token登录令牌"); List<ApiDocApi.Field> loginParamsFields = getParamsFields(loginApiDoc); ApiDocApi.Field regDatesField = loginParamsFields.stream().filter(getRegDates("regDates")).findAny().get(); assertEquals(regDatesField.getType(), "Date[]"); ApiDocApi.Field regDateArrayField = loginParamsFields .stream().filter(getRegDates("regDateArray")).findAny().get(); assertEquals(regDateArrayField.getType(), "Date[]"); assertNotNull(apis); }