diff options
author | 2020-11-02 11:31:39 +0000 | |
---|---|---|
committer | 2020-11-03 11:11:55 +0000 | |
commit | 47598117ee0b411cfc6fad323598f5644b51c9c9 (patch) | |
tree | efee41d2e1fa136247b4226ac2154cbbebfcf9bd | |
parent | 70c17020b7025a9ff18192d4d5add6f75ace49aa (diff) |
Swagger codegen using Spring framework
1. Pom.xml updated to generate API code using Swagger codegen.
2. Moved the createModule code to the method implemented by Swagger.
JIRA: https://jira.onap.org/browse/CCSDK-2897
Issue-ID: CCSDK-2897
Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca>
Change-Id: Iadd3dc0402f06a597a179148fd5f43e0fe7c48f6
Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca>
-rw-r--r-- | cps/cps-dependencies/pom.xml | 11 | ||||
-rw-r--r-- | cps/cps-parent/pom.xml | 28 | ||||
-rw-r--r-- | cps/cps-rest/docs/api/swagger/openapi.yml | 34 | ||||
-rw-r--r-- | cps/cps-rest/pom.xml | 13 | ||||
-rw-r--r-- | cps/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java | 77 |
5 files changed, 127 insertions, 36 deletions
diff --git a/cps/cps-dependencies/pom.xml b/cps/cps-dependencies/pom.xml index 6f50cd0fc..ad71b1158 100644 --- a/cps/cps-dependencies/pom.xml +++ b/cps/cps-dependencies/pom.xml @@ -17,6 +17,7 @@ <hibernate-types.version>2.10.0</hibernate-types.version> <spock-core.version>2.0-M2-groovy-3.0</spock-core.version> <springboot.version>2.3.3.RELEASE</springboot.version> + <springfox-swagger2.version>2.6.1</springfox-swagger2.version> <swagger.version>2.1.4</swagger.version> <yangtools.version>5.0.6</yangtools.version> </properties> @@ -48,6 +49,16 @@ <version>${swagger.version}</version> </dependency> <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-swagger2</artifactId> + <version>${springfox-swagger2.version}</version> + </dependency> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-swagger-ui</artifactId> + <version>${springfox-swagger2.version}</version> + </dependency> + <dependency> <groupId>com.vladmihalcea</groupId> <artifactId>hibernate-types-52</artifactId> <version>${hibernate-types.version}</version> diff --git a/cps/cps-parent/pom.xml b/cps/cps-parent/pom.xml index 2ddb2b668..db80970c5 100644 --- a/cps/cps-parent/pom.xml +++ b/cps/cps-parent/pom.xml @@ -22,6 +22,7 @@ <maven-replacer-plugin.version>1.5.3</maven-replacer-plugin.version> <oparent.version>3.1.0</oparent.version> <spring-boot-maven-plugin.version>2.3.3.RELEASE</spring-boot-maven-plugin.version> + <swagger-codegen-maven-plugin.version>3.0.18</swagger-codegen-maven-plugin.version> <swagger-ui.version>3.35.0</swagger-ui.version> </properties> @@ -78,6 +79,33 @@ </execution> </executions> </plugin> + <!-- Swagger code generation. --> + <plugin> + <groupId>io.swagger.codegen.v3</groupId> + <artifactId>swagger-codegen-maven-plugin</artifactId> + <version>${swagger-codegen-maven-plugin.version}</version> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + <configuration> + <inputSpec>${project.basedir}/docs/api/swagger/openapi.yml</inputSpec> + <invokerPackage>org.onap.cps.rest.controller</invokerPackage> + <modelPackage>org.onap.cps.rest.model</modelPackage> + <apiPackage>org.onap.cps.rest.api</apiPackage> + <language>spring</language> + <generateSupportingFiles>false</generateSupportingFiles> + <configOptions> + <sourceFolder>src/gen/java</sourceFolder> + <dateLibrary>java11</dateLibrary> + <interfaceOnly>true</interfaceOnly> + <useTags>true</useTags> + </configOptions> + </configuration> + </execution> + </executions> + </plugin> <plugin> <!-- Download Swagger UI webjar. --> <groupId>org.apache.maven.plugins</groupId> diff --git a/cps/cps-rest/docs/api/swagger/openapi.yml b/cps/cps-rest/docs/api/swagger/openapi.yml index f116c26ce..9b2ac1ec5 100644 --- a/cps/cps-rest/docs/api/swagger/openapi.yml +++ b/cps/cps-rest/docs/api/swagger/openapi.yml @@ -6,13 +6,13 @@ info: servers: - url: //localhost:8088/ tags: - - name: cps-resource + - name: cps-rest description: cps Resource paths: /v1/dataspaces/{dataspace-name}/: delete: tags: - - cps-resource + - cps-rest summary: Delete the given dataspace operationId: deleteDataspace parameters: @@ -41,7 +41,7 @@ paths: /v1/dataspaces/{dataspace-name}/anchors: get: tags: - - cps-resource + - cps-rest summary: Read all anchors, given a dataspace operationId: getAnchors parameters: @@ -69,7 +69,7 @@ paths: content: {} post: tags: - - cps-resource + - cps-rest summary: Create a new anchor in the given dataspace operationId: createAnchor parameters: @@ -86,9 +86,9 @@ paths: required: - file properties: - file: + multipartFile: type: string - description: file + description: multipartFile format: binary required: true responses: @@ -113,7 +113,7 @@ paths: /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}: get: tags: - - cps-resource + - cps-rest summary: Read an anchor given a anchor and a dataspace operationId: getAnchor parameters: @@ -147,7 +147,7 @@ paths: content: {} delete: tags: - - cps-resource + - cps-rest summary: Delete an anchor given a anchor and a dataspace operationId: deleteAnchor parameters: @@ -182,7 +182,7 @@ paths: /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes: get: tags: - - cps-resource + - cps-rest summary: Get a node given an anchor for the given dataspace operationId: getNodeByDataspaceAndAnchor parameters: @@ -225,7 +225,7 @@ paths: /v1/dataspaces/{dataspace-name}/modules: get: tags: - - cps-resource + - cps-rest summary: Read all yang modules in the store operationId: getModule parameters: @@ -263,7 +263,7 @@ paths: content: {} post: tags: - - cps-resource + - cps-rest summary: Create modules for the given dataspace operationId: createModules parameters: @@ -280,9 +280,9 @@ paths: required: - file properties: - file: + multipartFile: type: string - description: file + description: multipartFile format: binary required: true responses: @@ -307,7 +307,7 @@ paths: /v1/dataspaces/{dataspace-name}/nodes: get: tags: - - cps-resource + - cps-rest summary: Get all nodes for a given dataspace using an xpath or schema node identifier operationId: getNode parameters: @@ -343,7 +343,7 @@ paths: x-codegen-request-body-name: requestBody post: tags: - - cps-resource + - cps-rest summary: Create a node for a given anchor for the given dataspace operationId: createNode parameters: @@ -360,9 +360,9 @@ paths: required: - file properties: - file: + multipartFile: type: string - description: file + description: multipartFile format: binary required: true responses: diff --git a/cps/cps-rest/pom.xml b/cps/cps-rest/pom.xml index f9be75b7e..fcd97dcf7 100644 --- a/cps/cps-rest/pom.xml +++ b/cps/cps-rest/pom.xml @@ -43,6 +43,14 @@ <artifactId>swagger-jaxrs2</artifactId>
</dependency>
<dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger-ui</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
@@ -61,6 +69,11 @@ <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
+ <!-- Swagger code generation. -->
+ <plugin>
+ <groupId>io.swagger.codegen.v3</groupId>
+ <artifactId>swagger-codegen-maven-plugin</artifactId>
+ </plugin>
<plugin>
<!-- Download Swagger UI webjar. -->
<groupId>org.apache.maven.plugins</groupId>
diff --git a/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java b/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java index a577af70e..9a31b6d8e 100644 --- a/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java +++ b/cps/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java @@ -27,8 +27,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.persistence.PersistenceException; +import javax.validation.Valid; import org.hibernate.exception.ConstraintViolationException; import org.onap.cps.api.CpService; +import org.onap.cps.rest.api.CpsRestApi; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; import org.springframework.beans.factory.annotation.Autowired; @@ -44,38 +46,75 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController -public class CpsRestController { +public class CpsRestController implements CpsRestApi { @Autowired private CpService cpService; - /* - Old rest endpoints before contract first approach (Need to be removed). - */ + @Override + public ResponseEntity<Object> createAnchor(@Valid MultipartFile multipartFile, String dataspaceName) { + return null; + } - /** - * Upload a yang model file. - * - * @param uploadedFile the yang model Multipart File. - * @param dataspaceName the dataspace name linked to the model. - * @return a ResponseEntity. - */ - @PostMapping("/dataspaces/{dataspace_name}/modules") - public final ResponseEntity<String> uploadYangModelFile( - @RequestParam("file") MultipartFile uploadedFile, - @PathVariable("dataspace_name") String dataspaceName) { + @Override + public ResponseEntity<Object> createModules(@Valid MultipartFile multipartFile, String dataspaceName) { try { - final File fileToParse = saveToFile(uploadedFile); + final File fileToParse = saveToFile(multipartFile); final SchemaContext schemaContext = cpService.parseAndValidateModel(fileToParse); cpService.storeSchemaContext(schemaContext, dataspaceName); - return new ResponseEntity<String>("Resource successfully created", HttpStatus.CREATED); + return new ResponseEntity<>("Resource successfully created", HttpStatus.CREATED); } catch (final YangParserException | ConstraintViolationException e) { - return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } catch (final Exception e) { - return new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } + @Override + public ResponseEntity<Object> createNode(@Valid MultipartFile multipartFile, String dataspaceName) { + return null; + } + + @Override + public ResponseEntity<Object> deleteAnchor(String dataspaceName, String anchorName) { + return null; + } + + @Override + public ResponseEntity<Object> deleteDataspace(String dataspaceName) { + return null; + } + + @Override + public ResponseEntity<Object> getAnchor(String dataspaceName, String anchorName) { + return null; + } + + @Override + public ResponseEntity<Object> getAnchors(String dataspaceName) { + return null; + } + + @Override + public ResponseEntity<Object> getModule(String dataspaceName, @Valid String namespaceName, @Valid String revision) { + return null; + } + + @Override + public ResponseEntity<Object> getNode(@Valid String body, String dataspaceName) { + return null; + } + + @Override + public ResponseEntity<Object> getNodeByDataspaceAndAnchor(@Valid String body, String dataspaceName, + String anchorName) { + return null; + } + + /* + Old rest endpoints before contract first approach (Need to be removed). + */ + /** * Upload a JSON file. * |