summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Determe <sd378r@intl.att.com>2018-03-15 09:47:14 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-15 09:47:14 +0000
commit17b5881be20b37a8e6054ddf6002d9e29b761974 (patch)
treeb2555246740a53c5e56f27defcfa2397d90b6086
parent9e0cc8c2927906e69646ebac3e7d0b716136f6ff (diff)
parent009f713c6c46cf3647f1a008e3a963522f988f92 (diff)
Merge "Add swagger generation for jaxrs api"
-rw-r--r--README.md4
-rw-r--r--pom.xml17
-rw-r--r--src/main/java/org/onap/clamp/clds/service/JaxrsApplication.java42
3 files changed, 63 insertions, 0 deletions
diff --git a/README.md b/README.md
index 4fe12ff23..ea061ce3c 100644
--- a/README.md
+++ b/README.md
@@ -88,3 +88,7 @@ Once the image has been built and is available locally, you can use the `docker-
Clamp uses logback framework to generate logs. The logback.xml file cand be found under the [src/main/resources/ folder](src/main/resources).
With the default log settings, all logs will be generated into console and into root.log file under the Clamp root folder. The root.log file is not allowed to be appended, thus restarting the clamp will result in cleaning of the old log files.
+
+### Api
+
+You can see the swagger definition for the jaxrs apis at `/restservices/clds/v1/openapi.json` \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 69755e47d..0d97cf6e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -70,6 +70,8 @@
<project.scm.id>git-server</project.scm.id>
<java.version>1.8</java.version>
+ <swagger.jaxrs2.version>2.0.0-rc4</swagger.jaxrs2.version>
+ <guava.version>20.0</guava.version>
<eelf.core.version>1.0.0</eelf.core.version>
<camel.version>2.20.1</camel.version>
<springboot.version>1.5.10.RELEASE</springboot.version>
@@ -168,6 +170,17 @@
</dependencyManagement>
<dependencies>
+ <!-- Swagger requires at least v20 and policy is bringing version 14 -->
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guava.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.swagger.core.v3</groupId>
+ <artifactId>swagger-jaxrs2</artifactId>
+ <version>${swagger.jaxrs2.version}</version>
+ </dependency>
<dependency>
<groupId>com.att.eelf</groupId>
<artifactId>eelf-core</artifactId>
@@ -304,6 +317,10 @@
<version>1.1.0</version>
<exclusions>
<exclusion>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </exclusion>
+ <exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
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