-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cloud-stream): search configuration classes for channels and operations #690
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,19 +25,20 @@ public class FunctionalChannelBeanBuilder { | |
public Set<FunctionalChannelBeanData> build(AnnotatedElement element) { | ||
Class<?> type = getRawType(element); | ||
|
||
if (Consumer.class.isAssignableFrom(type)) { | ||
Class<?> payloadType = getTypeGenerics(element).get(0); | ||
List<Class<?>> typeGenerics = getTypeGenerics(element); | ||
if (Consumer.class.isAssignableFrom(type) && typeGenerics.size() >= 1) { | ||
Class<?> payloadType = typeGenerics.get(0); | ||
return Set.of(ofConsumer(element, payloadType)); | ||
} | ||
|
||
if (Supplier.class.isAssignableFrom(type)) { | ||
Class<?> payloadType = getTypeGenerics(element).get(0); | ||
if (Supplier.class.isAssignableFrom(type) && typeGenerics.size() >= 1) { | ||
Class<?> payloadType = typeGenerics.get(0); | ||
return Set.of(ofSupplier(element, payloadType)); | ||
} | ||
|
||
if (Function.class.isAssignableFrom(type)) { | ||
Class<?> inputType = getTypeGenerics(element).get(0); | ||
Class<?> outputType = getTypeGenerics(element).get(1); | ||
if (Function.class.isAssignableFrom(type) && typeGenerics.size() >= 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be too defensive, |
||
Class<?> inputType = typeGenerics.get(0); | ||
Class<?> outputType = typeGenerics.get(1); | ||
|
||
return Set.of(ofConsumer(element, inputType), ofSupplier(element, outputType)); | ||
} | ||
|
@@ -89,8 +90,11 @@ private static String getElementName(AnnotatedElement element) { | |
|
||
private List<Class<?>> getTypeGenerics(AnnotatedElement element) { | ||
if (element instanceof Method m) { | ||
ParameterizedType genericReturnType = (ParameterizedType) m.getGenericReturnType(); | ||
return getTypeGenerics(genericReturnType); | ||
if (m.getGenericReturnType() instanceof ParameterizedType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not add the type check because we are always dealing here with methods that return if (m.getGenericReturnType() instanceof ParameterizedType parameterizedType) {
return getTypeGenerics(parameterizedType);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did run into an exception, but could have been an intermediate state. |
||
ParameterizedType genericReturnType = (ParameterizedType) m.getGenericReturnType(); | ||
return getTypeGenerics(genericReturnType); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
if (element instanceof Class<?> c) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
import io.github.springwolf.core.asyncapi.components.headers.AsyncHeadersNotDocumented; | ||
import io.github.springwolf.core.asyncapi.scanners.OperationsScanner; | ||
import io.github.springwolf.core.asyncapi.scanners.beans.BeanMethodsScanner; | ||
import io.github.springwolf.core.asyncapi.scanners.classes.spring.ComponentClassScanner; | ||
import io.github.springwolf.core.asyncapi.scanners.classes.SpringwolfClassScanner; | ||
import io.github.springwolf.core.asyncapi.scanners.operations.OperationMerger; | ||
import io.github.springwolf.core.configuration.docket.AsyncApiDocket; | ||
import io.github.springwolf.core.configuration.docket.AsyncApiDocketService; | ||
|
@@ -39,15 +39,15 @@ public class CloudStreamFunctionOperationsScanner implements OperationsScanner { | |
|
||
private final AsyncApiDocketService asyncApiDocketService; | ||
private final BeanMethodsScanner beanMethodsScanner; | ||
private final ComponentClassScanner componentClassScanner; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as first comment, the use of |
||
private final SpringwolfClassScanner classScanner; | ||
private final ComponentsService componentsService; | ||
private final BindingServiceProperties cloudStreamBindingsProperties; | ||
private final FunctionalChannelBeanBuilder functionalChannelBeanBuilder; | ||
|
||
@Override | ||
public Map<String, Operation> scan() { | ||
Set<AnnotatedElement> elements = new HashSet<>(); | ||
elements.addAll(componentClassScanner.scan()); | ||
elements.addAll(classScanner.scan()); | ||
elements.addAll(beanMethodsScanner.getBeanMethods()); | ||
|
||
List<Map.Entry<String, Operation>> operations = elements.stream() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
ComponentClassScanner
and notSpringwolfClassScanner
is intentional.SpringwolfClassScanner
will return classes annotated with@Component
which is needed here, but also classes returned by bean methods. In the case of spring cloud stream functions, the bean method always has generics, which can't be retrieved (to my knowledge) from theClass
object.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Therefore both scanners are needed.
My intention is to support Configuration annotations as well. And overall to align the cloudstream with the other plugins - if possible.
Will have a closer look, whether Configurations are Components already