summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorBertozzi, Julien (jb379x) <jb379x@att.com>2018-03-08 15:53:57 -0500
committerBertozzi, Julien (jb379x) <jb379x@att.com>2018-03-14 09:04:11 -0400
commit009f713c6c46cf3647f1a008e3a963522f988f92 (patch)
tree14a3ab53d791689e11a756229833f95223b6b330 /src/main/java
parent6156e258a8b9df35d2c2c8872a2213b21a446523 (diff)
Add swagger generation for jaxrs api
Issue-ID: CLAMP-137 Change-Id: I0b1e088a99a7e1c63dc0b0f4a36b16020181bf1f Signed-off-by: Bertozzi, Julien (jb379x) <jb379x@att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/clds/service/JaxrsApplication.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/org/onap/clamp/clds/service/JaxrsApplication.java b/src/main/java/org/onap/clamp/clds/service/JaxrsApplication.java
index d6e74aef1..702e06499 100644
--- a/src/main/java/org/onap/clamp/clds/service/JaxrsApplication.java
+++ b/src/main/java/org/onap/clamp/clds/service/JaxrsApplication.java
@@ -23,12 +23,54 @@
package org.onap.clamp.clds.service;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
+import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Component;
@Component
@ApplicationPath("/restservices/clds/v1")
public class JaxrsApplication extends Application {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(JaxrsApplication.class);
+
+ private Function<BeanDefinition, Optional<Class<?>>> beanDefinitionToClass = b -> {
+ try {
+ return Optional.of(Class.forName(b.getBeanClassName()));
+ } catch (ClassNotFoundException e) {
+ logger.error("Could not get class annotated with @Path for swagger documentation generation", e);
+ return Optional.empty();
+ }
+ };
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> resources = new HashSet<>();
+ resources.add(io.swagger.v3.jaxrs2.integration.resources.OpenApiResource.class);
+ resources.addAll(scan());
+ return resources;
+ }
+
+ private List<Class<?>> scan() {
+ ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
+ scanner.addIncludeFilter(new AnnotationTypeFilter(javax.ws.rs.Path.class));
+ return scanner.findCandidateComponents("org.onap.clamp.clds").stream()
+ .map(beanDefinitionToClass)
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .collect(Collectors.toList());
+ }
+
} \ No newline at end of file