diff options
author | 2020-10-19 12:48:06 +0100 | |
---|---|---|
committer | 2020-10-22 10:45:06 +0100 | |
commit | f7ba359b048cb6f7dc12a00df872b9c19eda76ba (patch) | |
tree | d96dce2656e3883b2c2815c9856b195e503bb651 | |
parent | 6f523dbc6659ff5793f6707a71f2c401e1148d83 (diff) |
Adding swagger codegen
Jira Link: https://jira.onap.org/browse/CCSDK-2907
Issue-ID: CCSDK-2907
Signed-off-by: Niamh Core <niamh.core@est.tech>
Change-Id: I07c27cd1709f9bc19d67443daaf0c9c59507a5a0
-rw-r--r-- | cps/cps-rest/docs/api/swagger/openapi.yml | 402 | ||||
-rw-r--r-- | cps/cps-rest/pom.xml | 57 | ||||
-rw-r--r-- | cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java | 2 | ||||
-rw-r--r-- | cps/cps-rest/src/main/java/org/onap/cps/rest/controller/RestController.java | 65 | ||||
-rw-r--r-- | cps/pom.xml | 35 |
5 files changed, 535 insertions, 26 deletions
diff --git a/cps/cps-rest/docs/api/swagger/openapi.yml b/cps/cps-rest/docs/api/swagger/openapi.yml new file mode 100644 index 000000000..1f9019a63 --- /dev/null +++ b/cps/cps-rest/docs/api/swagger/openapi.yml @@ -0,0 +1,402 @@ +openapi: 3.0.1 +info: + title: CPS API + description: Configuration Persistence Service API + version: "1.0" +servers: + - url: //localhost:8088/ +tags: + - name: cps-resource + description: cps Resource +paths: + /v1/dataspaces/{dataspace-name}/: + delete: + tags: + - cps-resource + summary: Delete the given dataspace + operationId: deleteDataspace + parameters: + - name: dataspace-name + in: path + description: dataspace-name + required: true + schema: + type: integer + format: int32 + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 204: + description: No Content + content: {} + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + /v1/dataspaces/{dataspace-name}/anchors: + get: + tags: + - cps-resource + summary: Read all anchors, given a dataspace + operationId: getAnchors + parameters: + - name: dataspace-name + in: path + description: dataspace-name + required: true + schema: + type: integer + format: int32 + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} + post: + tags: + - cps-resource + summary: Create a new anchor in the given dataspace + operationId: createAnchor + parameters: + - name: dataspace-name + in: path + description: dataspace-name + required: true + schema: + type: integer + format: int32 + requestBody: + content: + multipart/form-data: + schema: + required: + - file + properties: + file: + type: string + description: file + format: binary + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 201: + description: Created + content: {} + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} + /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}: + get: + tags: + - cps-resource + summary: Read an anchor given a anchor and a dataspace + operationId: getAnchor + parameters: + - name: dataspace-name + in: path + description: dataspace-name + required: true + schema: + type: integer + format: int32 + - name: anchor-name + in: path + description: anchor-name + required: true + schema: + type: integer + format: int32 + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} + delete: + tags: + - cps-resource + summary: Delete an anchor given a anchor and a dataspace + operationId: deleteAnchor + parameters: + - name: dataspace-name + in: path + description: dataspace-name + required: true + schema: + type: integer + format: int32 + - name: anchor-name + in: path + description: anchor-name + required: true + schema: + type: integer + format: int32 + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 204: + description: No Content + content: {} + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes: + get: + tags: + - cps-resource + summary: Get a node given an anchor for the given dataspace + operationId: getNodeByDataspaceAndAnchor + parameters: + - name: dataspaceName + in: path + description: dataspaceName + required: true + schema: + type: integer + format: int32 + - name: anchorpoint + in: path + description: anchorpoint + required: true + schema: + type: integer + format: int32 + requestBody: + description: xpath + content: + application/json: + schema: + type: string + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} + x-codegen-request-body-name: xpath + /v1/dataspaces/{dataspace-name}/modules: + get: + tags: + - cps-resource + summary: Read all yang modules in the store + operationId: getModule + parameters: + - name: dataspaceName + in: path + description: dataspaceName + required: true + schema: + type: integer + format: int32 + - name: namespace-name + in: query + description: namespace-name + schema: + type: integer + format: int32 + - name: revision + in: query + description: revision + schema: + type: integer + format: int32 + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} + post: + tags: + - cps-resource + summary: Create modules for the given dataspace + operationId: createModules + parameters: + - name: dataspace-name + in: path + description: dataspace-name + required: true + schema: + type: integer + format: int32 + requestBody: + content: + multipart/form-data: + schema: + required: + - file + properties: + file: + type: string + description: file + format: binary + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 201: + description: Created + content: {} + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} + /v1/dataspaces/{dataspace-name}/nodes: + get: + tags: + - cps-resource + summary: Get all nodes for a given dataspace using an xpath or schema node identifier + operationId: getNode + parameters: + - name: dataspaceName + in: path + description: dataspaceName + required: true + schema: + type: integer + format: int32 + requestBody: + description: requestBody + content: + application/json: + schema: + type: string + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} + x-codegen-request-body-name: requestBody + post: + tags: + - cps-resource + summary: Create a node for a given anchor for the given dataspace + operationId: createNode + parameters: + - name: dataspace-name + in: path + description: dataspace-name + required: true + schema: + type: integer + format: int32 + requestBody: + content: + multipart/form-data: + schema: + required: + - file + properties: + file: + type: string + description: file + format: binary + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 201: + description: Created + content: {} + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} +components: {} diff --git a/cps/cps-rest/pom.xml b/cps/cps-rest/pom.xml index 274e57f52..3cecc5f73 100644 --- a/cps/cps-rest/pom.xml +++ b/cps/cps-rest/pom.xml @@ -1,6 +1,6 @@ <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cps-rest</artifactId>
<parent>
@@ -72,6 +72,21 @@ </exclusion>
</exclusions>
</dependency>
+
+ <!-- Used by the generated API -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-bundle-jaxrs</artifactId>
+ <version>${cxf-bundle-jaxrs.version}</version>
+ </dependency>
+
+ <!-- Used by the generated API -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-service-description</artifactId>
+ <version>${cxf-rt-rs-service.version}</version>
+ </dependency>
+
</dependencies>
<build>
@@ -88,6 +103,33 @@ </execution>
</executions>
</plugin>
+
+ <plugin>
+ <groupId>io.swagger.codegen.v3</groupId>
+ <artifactId>swagger-codegen-maven-plugin</artifactId>
+ <version>${swagger-codegen.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.controller</apiPackage>
+ <language>jaxrs-cxf</language>
+ <generateSupportingFiles>true</generateSupportingFiles>
+ <configOptions>
+ <sourceFolder>src/gen/java</sourceFolder>
+ <dateLibrary>java8</dateLibrary>
+ <library>jersey2</library>
+ <interfaceOnly>true</interfaceOnly>
+ </configOptions>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<!-- Download Swagger UI webjar. -->
<groupId>org.apache.maven.plugins</groupId>
@@ -107,7 +149,9 @@ <version>${swagger-ui.version}</version>
</artifactItem>
</artifactItems>
- <outputDirectory>${project.build.directory}/swagger-ui-${swagger-ui.version}</outputDirectory>
+ <outputDirectory>
+ ${project.build.directory}/swagger-ui-${swagger-ui.version}
+ </outputDirectory>
</configuration>
</execution>
</executions>
@@ -125,10 +169,13 @@ <goal>copy-resources</goal>
</goals>
<configuration>
- <outputDirectory>${project.build.outputDirectory}/static/swagger-ui</outputDirectory>
+ <outputDirectory>${project.build.outputDirectory}/static/swagger-ui
+ </outputDirectory>
<resources>
<resource>
- <directory>${project.build.directory}/swagger-ui-${swagger-ui.version}/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/</directory>
+ <directory>
+ ${project.build.directory}/swagger-ui-${swagger-ui.version}/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/
+ </directory>
<excludes>
<exclude>**/*.gz</exclude>
</excludes>
diff --git a/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java b/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java index ac781d337..553c16b55 100644 --- a/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java +++ b/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java @@ -34,7 +34,7 @@ import org.onap.cps.rest.controller.RestController; import org.springframework.context.annotation.Configuration;
@Configuration
-@ApplicationPath("/api/cps")
+@ApplicationPath("api")
public class JerseyConfig extends ResourceConfig {
/**
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 e86d329ba..18e24b437 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,7 +23,9 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import java.io.File; import java.io.IOException; +import java.io.InputStream; import javax.persistence.PersistenceException; +import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -34,6 +36,9 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.SecurityContext; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; import org.onap.cps.api.CpService; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -41,14 +46,66 @@ import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; - - -@Path("v1") -public class RestController { +@Path("cps") +public class RestController implements CpsResourceApi { @Autowired private CpService cpService; + @Override + public Object createAnchor(Attachment fileDetail, Integer dataspaceName) { + return null; + } + + @Override + public Object createModules(Attachment fileDetail, Integer dataspaceName) { + return null; + } + + @Override + public Object createNode(Attachment fileDetail, Integer dataspaceName) { + return null; + } + + @Override + public Object deleteAnchor(Integer dataspaceName, Integer anchorName) { + return null; + } + + @Override + public Object deleteDataspace(Integer dataspaceName) { + return null; + } + + @Override + public Object getAnchor(Integer dataspaceName, Integer anchorName) { + return null; + } + + @Override + public Object getAnchors(Integer dataspaceName) { + return null; + } + + @Override + public Object getModule(Integer dataspaceName, Integer namespaceName, Integer revision) { + return null; + } + + @Override + public Object getNode(@Valid String body, Integer dataspaceName) { + return null; + } + + @Override + public Object getNodeByDataspaceAndAnchor(@Valid String body, Integer dataspaceName, Integer anchorpoint) { + return null; + } + + /* + Old rest endpoints before contract first approach (Need to be removed). + */ + /** * Upload a yang model file. * diff --git a/cps/pom.xml b/cps/pom.xml index 4e9ca39db..dd98ca586 100644 --- a/cps/pom.xml +++ b/cps/pom.xml @@ -18,20 +18,23 @@ <url>http://www.onap.org/</url>
</organization>
- <properties>
- <java.version>11</java.version>
- <springboot.version>2.3.3.RELEASE</springboot.version>
- <oparent.version>3.1.0</oparent.version>
- <yangtools.version>5.0.6</yangtools.version>
- <swagger.version>2.1.4</swagger.version>
- <groovy.version>3.0.6</groovy.version>
- <spock-core.version>2.0-M2-groovy-3.0</spock-core.version>
- <maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
- <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
- <maven-replacer-plugin.version>1.5.3</maven-replacer-plugin.version>
- <swagger-ui.version>3.35.0</swagger-ui.version>
- <hibernate-types.version>2.10.0</hibernate-types.version>
- </properties>
+ <properties>
+ <java.version>11</java.version>
+ <springboot.version>2.3.3.RELEASE</springboot.version>
+ <oparent.version>3.1.0</oparent.version>
+ <yangtools.version>5.0.6</yangtools.version>
+ <swagger.version>2.1.4</swagger.version>
+ <groovy.version>3.0.6</groovy.version>
+ <spock-core.version>2.0-M2-groovy-3.0</spock-core.version>
+ <swagger-codegen.version>3.0.18</swagger-codegen.version>
+ <cxf-rt-rs-service.version>3.0.0</cxf-rt-rs-service.version>
+ <cxf-bundle-jaxrs.version>2.2.9</cxf-bundle-jaxrs.version>
+ <maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
+ <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
+ <maven-replacer-plugin.version>1.5.3</maven-replacer-plugin.version>
+ <swagger-ui.version>3.35.0</swagger-ui.version>
+ <hibernate-types.version>2.10.0</hibernate-types.version>
+ </properties>
<dependencyManagement>
<dependencies>
@@ -113,7 +116,7 @@ <!-- Mandatory plugins for using Spock -->
<plugin>
- <!-- The gmavenplus plugin is used to compile Groovy code.
+ <!-- The gmavenplus plugin is used to compile Groovy code.
To learn more about this plugin, visit https://github.com/groovy/GMavenPlus/wiki -->
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
@@ -126,7 +129,7 @@ </execution>
</executions>
</plugin>
- <!-- Required because names of spec classes don't match default
+ <!-- Required because names of spec classes don't match default
Surefire patterns (`*Test` etc.) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
|