From 009f713c6c46cf3647f1a008e3a963522f988f92 Mon Sep 17 00:00:00 2001 From: "Bertozzi, Julien (jb379x)" Date: Thu, 8 Mar 2018 15:53:57 -0500 Subject: Add swagger generation for jaxrs api Issue-ID: CLAMP-137 Change-Id: I0b1e088a99a7e1c63dc0b0f4a36b16020181bf1f Signed-off-by: Bertozzi, Julien (jb379x) --- README.md | 4 +++ pom.xml | 17 +++++++++ .../onap/clamp/clds/service/JaxrsApplication.java | 42 ++++++++++++++++++++++ 3 files changed, 63 insertions(+) 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 2f1a7d248..9591e7f9e 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,8 @@ git-server 1.8 + 2.0.0-rc4 + 20.0 1.0.0 2.20.1 1.5.10.RELEASE @@ -168,6 +170,17 @@ + + + com.google.guava + guava + ${guava.version} + + + io.swagger.core.v3 + swagger-jaxrs2 + ${swagger.jaxrs2.version} + com.att.eelf eelf-core @@ -303,6 +316,10 @@ PolicyEngineAPI 1.1.0 + + com.google.guava + guava + log4j log4j 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>> 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> getClasses() { + Set> resources = new HashSet<>(); + resources.add(io.swagger.v3.jaxrs2.integration.resources.OpenApiResource.class); + resources.addAll(scan()); + return resources; + } + + private List> 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 -- cgit 1.2.3-korg