in shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java [181:239]
private List<ApiDocRegisterDTO> buildApiDocDTO(final Object bean, final Method method, final Map<String, T> beans) {
AtomicBoolean generated = new AtomicBoolean(false);
Pair<String, List<String>> pairs = Stream.of(method.getDeclaredAnnotations()).filter(ApiDoc.class::isInstance).findAny().map(item -> {
ApiDoc apiDoc = (ApiDoc) item;
generated.set(apiDoc.generated());
String[] tags = apiDoc.tags();
List<String> tagsList = new ArrayList<>();
if (tags.length > 0 && StringUtils.isNotBlank(tags[0])) {
tagsList = Arrays.asList(tags);
}
return Pair.of(apiDoc.desc(), tagsList);
}).orElse(Pair.of("", new ArrayList<>()));
if (!generated.get()) {
return Collections.emptyList();
}
Class<?> clazz = AopUtils.isAopProxy(bean) ? AopUtils.getTargetClass(bean) : bean.getClass();
String superPath = buildApiSuperPath(clazz, AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType()));
if (superPath.contains("*")) {
superPath = superPath.substring(0, superPath.lastIndexOf("/"));
}
Annotation annotation = AnnotatedElementUtils.findMergedAnnotation(clazz, getAnnotationType());
if (Objects.isNull(annotation)) {
return Lists.newArrayList();
}
Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, String> sextet = buildApiDocSextet(method, annotation, beans);
if (Objects.isNull(sextet)) {
return Lists.newArrayList();
}
String contextPath = getContextPath();
String[] value0 = sextet.getValue0();
List<ApiDocRegisterDTO> list = Lists.newArrayList();
for (String value : value0) {
String apiPath = pathJoin(contextPath, superPath, value);
ApiHttpMethodEnum[] value3 = sextet.getValue3();
for (ApiHttpMethodEnum apiHttpMethodEnum : value3) {
String documentJson = buildDocumentJson(pairs.getRight(), apiPath, method);
String extJson = buildExtJson(method);
ApiDocRegisterDTO build = ApiDocRegisterDTO.builder()
.consume(sextet.getValue1())
.produce(sextet.getValue2())
.httpMethod(apiHttpMethodEnum.getValue())
.contextPath(contextPath)
.ext(extJson)
.document(documentJson)
.rpcType(sextet.getValue4().getName())
.version(sextet.getValue5())
.apiDesc(pairs.getLeft())
.tags(pairs.getRight())
.apiPath(apiPath)
.apiSource(ApiSourceEnum.ANNOTATION_GENERATION.getValue())
.state(ApiStateEnum.UNPUBLISHED.getState())
.apiOwner("admin")
.eventType(EventType.REGISTER)
.build();
list.add(build);
}
}
return list;
}