use of act.apidoc.Endpoint.ParamInfo in project actframework by actframework.
the class ApiManager method exploreDescriptions.
private void exploreDescriptions(Set<Class> controllerClasses) {
DevModeClassLoader cl = $.cast(Act.app().classLoader());
Map<String, Javadoc> methodJavaDocs = new HashMap<>();
for (Class controllerClass : controllerClasses) {
Source src = cl.source(controllerClass);
if (null == src) {
continue;
}
try {
CompilationUnit compilationUnit = JavaParser.parse(IO.reader(src.code()), true);
List<TypeDeclaration> types = compilationUnit.getTypes();
for (TypeDeclaration type : types) {
if (type instanceof ClassOrInterfaceDeclaration) {
exploreDeclaration((ClassOrInterfaceDeclaration) type, methodJavaDocs, "");
}
}
} catch (Exception e) {
LOGGER.warn(e, "error parsing source for " + controllerClass);
}
}
for (Endpoint endpoint : endpoints) {
Javadoc javadoc = methodJavaDocs.get(endpoint.getId());
if (null != javadoc) {
String desc = javadoc.getDescription().toText();
if (S.notBlank(desc)) {
endpoint.setDescription(desc);
}
List<ParamInfo> params = endpoint.getParams();
if (params.isEmpty()) {
continue;
}
Map<String, ParamInfo> paramLookup = new HashMap<>();
for (ParamInfo param : params) {
paramLookup.put(param.getName(), param);
}
List<JavadocBlockTag> blockTags = javadoc.getBlockTags();
for (JavadocBlockTag tag : blockTags) {
if ("param".equals(tag.getTagName())) {
String paramName = tag.getName().get();
ParamInfo paramInfo = paramLookup.get(paramName);
if (null != paramInfo) {
paramInfo.setDescription(tag.getContent().toText());
}
}
}
}
}
}
Aggregations