Skip to content

Commit

Permalink
Merge pull request microprofile#441 from phillip-kruger/master
Browse files Browse the repository at this point in the history
Allow scanning with filter to only include certain scanners.
  • Loading branch information
phillip-kruger authored Aug 21, 2020
2 parents c30a0fa + f4a4870 commit f40a9b9
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.smallrye.openapi.runtime.scanner;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -96,18 +97,21 @@ public OpenApiAnnotationScanner(OpenApiConfig config, ClassLoader loader, IndexV
* Scan the deployment for relevant annotations. Returns an OpenAPI data model that was
* built from those found annotations.
*
* @param filter Filter to only include certain scanners. Based on the scanner name. (JAX-RS, Spring, Vert.x)
* @return OpenAPI generated from scanning annotations
*/
public OpenAPI scan() {
public OpenAPI scan(String... filter) {
// First scan the MicroProfile OpenAPI Annotations. Maybe later we can load this with SPI as well, and allow other Annotation sets.
OpenAPI openApi = scanMicroProfileOpenApiAnnotations();

// Now load all entry points with SPI and scan those
List<AnnotationScanner> annotationScanners = annotationScannerFactory.getAnnotationScanners();
for (AnnotationScanner annotationScanner : annotationScanners) {
ScannerLogging.logger.scanning(annotationScanner.getName());
CurrentScannerInfo.register(annotationScanner);
openApi = annotationScanner.scan(annotationScannerContext, openApi);
if (filter == null || filter.length == 0 || Arrays.asList(filter).contains(annotationScanner.getName())) {
ScannerLogging.logger.scanning(annotationScanner.getName());
CurrentScannerInfo.register(annotationScanner);
openApi = annotationScanner.scan(annotationScannerContext, openApi);
}
}
return openApi;
}
Expand Down

0 comments on commit f40a9b9

Please sign in to comment.