From 5654561386856a7816a7f4e00cef746bc2facedc Mon Sep 17 00:00:00 2001 From: Bruno Sakoto Date: Thu, 1 Oct 2020 23:47:01 -0400 Subject: [PATCH] Introduce swagger configuration Issue-ID: CCSDK-2754 Change-Id: I22bd50431ad24202dc84dd982bf7e7d2388ee981 Signed-off-by: Bruno Sakoto --- cps/cps-rest/pom.xml | 16 +++++++++ .../org/onap/cps/rest/config/SpringFoxConfig.java | 38 ++++++++++++++++++++++ .../onap/cps/rest/controller/RestController.java | 14 ++++++++ 3 files changed, 68 insertions(+) create mode 100644 cps/cps-rest/src/main/java/org/onap/cps/rest/config/SpringFoxConfig.java 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 @@ spring-boot-starter-jetty + + org.springframework.boot + spring-boot-starter-web + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + + io.springfox + springfox-swagger-ui + 2.9.2 + org.springframework.boot 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 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. * -- 2.16.6