Skip to content

Commit

Permalink
fix: search for TemplateVariableProviderFactory including ancestors
Browse files Browse the repository at this point in the history
to retrieve SecretTemplateVariableProviderFactory
  • Loading branch information
remibaptistegio committed Dec 18, 2024
1 parent 407511e commit a3b268b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.gravitee.resource.api.ResourceManager;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -153,10 +154,9 @@ public ApiReactor<T> create(final T reactableApi) {
protected List<TemplateVariableProvider> commonTemplateVariableProviders(T reactableApi) {
final List<TemplateVariableProvider> templateVariableProviders = new ArrayList<>();
templateVariableProviders.add(new ApiTemplateVariableProvider(reactableApi));
List<TemplateVariableProvider> list = applicationContext
.getBeansOfType(TemplateVariableProviderFactory.class)
.values()
.stream()
List<TemplateVariableProvider> list = Stream
.of(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, TemplateVariableProviderFactory.class))
.map(name -> (TemplateVariableProviderFactory) applicationContext.getBean(name))
.filter(factory -> factory.getTemplateVariableScope() == TemplateVariableScope.API)
.flatMap(factory -> factory.getTemplateVariableProviders().stream())
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ private List<TemplateVariableProvider> registerApiTemplateVariableProvider(List<
TemplateVariableProviderFactory apiTemplateVariableProviderFactory = mock(ApiTemplateVariableProviderFactory.class);
when(apiTemplateVariableProviderFactory.getTemplateVariableProviders()).thenReturn(providers);
when(apiTemplateVariableProviderFactory.getTemplateVariableScope()).thenReturn(TemplateVariableScope.API);
lenient()
.when(applicationContext.getBeansOfType(TemplateVariableProviderFactory.class))
.thenReturn(Map.of("apiTemplateVariableProviderFactory", apiTemplateVariableProviderFactory));
String[] providersName = { "apiTemplateVariableProviderFactory" };
lenient().when(applicationContext.getBeanNamesForType(TemplateVariableProviderFactory.class)).thenReturn(providersName);
lenient().when(applicationContext.getBean("apiTemplateVariableProviderFactory")).thenReturn(apiTemplateVariableProviderFactory);
return providers;
}

Expand Down

0 comments on commit a3b268b

Please sign in to comment.