aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Sakoto <bruno.sakoto@bell.ca>2020-10-01 23:47:01 -0400
committerBruno Sakoto <bruno.sakoto@bell.ca>2020-10-01 23:48:19 -0400
commit5654561386856a7816a7f4e00cef746bc2facedc (patch)
treef58b9011424c0af9b4e2eebb62bbda8949bf40d0
parentdce3695032ff3320fc7bfee46c4e36fde6d98883 (diff)
Introduce swagger configuration
Issue-ID: CCSDK-2754 Change-Id: I22bd50431ad24202dc84dd982bf7e7d2388ee981 Signed-off-by: Bruno Sakoto <bruno.sakoto@bell.ca>
-rw-r--r--cps/cps-rest/pom.xml16
-rw-r--r--cps/cps-rest/src/main/java/org/onap/cps/rest/config/SpringFoxConfig.java38
-rw-r--r--cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java14
3 files changed, 68 insertions, 0 deletions
diff --git a/cps/cps-rest/pom.xml b/cps/cps-rest/pom.xml
index bd9be8dfde..253c29c517 100644
--- a/cps/cps-rest/pom.xml
+++ b/cps/cps-rest/pom.xml
@@ -44,6 +44,22 @@
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger2</artifactId>
+ <version>2.9.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger-ui</artifactId>
+ <version>2.9.2</version>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
diff --git a/cps/cps-rest/src/main/java/org/onap/cps/rest/config/SpringFoxConfig.java b/cps/cps-rest/src/main/java/org/onap/cps/rest/config/SpringFoxConfig.java
new file mode 100644
index 0000000000..3a9e539472
--- /dev/null
+++ b/cps/cps-rest/src/main/java/org/onap/cps/rest/config/SpringFoxConfig.java
@@ -0,0 +1,38 @@
+package org.onap.cps.rest.config;
+
+
+import static springfox.documentation.builders.PathSelectors.regex;
+
+import com.google.common.base.Predicate;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+/**
+ * Swagger configuration.
+ */
+@Configuration
+@EnableSwagger2
+public class SpringFoxConfig {
+
+ /**
+ * Define api configuration.
+ */
+ @Bean
+ public Docket api() {
+ return new Docket(DocumentationType.SWAGGER_2)
+ .select()
+ .apis(RequestHandlerSelectors.any())
+ .paths(paths())
+ .build();
+ }
+
+ private Predicate<String> paths() {
+ return regex("/model.*");
+ }
+
+}
+
diff --git a/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java b/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java
index a64cd6a045..9b7c0008e7 100644
--- a/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java
+++ b/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java
@@ -23,6 +23,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
+import java.util.UUID;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -35,9 +36,15 @@ import org.onap.cps.api.CpService;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.multipart.MultipartFile;
@Path("cps")
+@org.springframework.web.bind.annotation.RestController
public class RestController {
@Autowired
@@ -66,6 +73,13 @@ public class RestController {
}
}
+ @PostMapping("/model")
+ @ResponseStatus(HttpStatus.CREATED)
+ public String addModel(@RequestParam("file") MultipartFile file) {
+ // Store and return a model dto ...
+ return UUID.randomUUID() + " : " + file.getOriginalFilename();
+ }
+
/**
* Upload a JSON file.
*