From: niamhcore Date: Mon, 19 Oct 2020 11:48:06 +0000 (+0100) Subject: Adding swagger codegen X-Git-Tag: 0.0.1~120^2~8 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=f7ba359b048cb6f7dc12a00df872b9c19eda76ba;p=cps.git Adding swagger codegen Jira Link: https://jira.onap.org/browse/CCSDK-2907 Issue-ID: CCSDK-2907 Signed-off-by: Niamh Core Change-Id: I07c27cd1709f9bc19d67443daaf0c9c59507a5a0 --- 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 @@ + 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"> 4.0.0 cps-rest @@ -72,6 +72,21 @@ + + + + org.apache.cxf + cxf-bundle-jaxrs + ${cxf-bundle-jaxrs.version} + + + + + org.apache.cxf + cxf-rt-rs-service-description + ${cxf-rt-rs-service.version} + + @@ -88,6 +103,33 @@ + + + io.swagger.codegen.v3 + swagger-codegen-maven-plugin + ${swagger-codegen.version} + + + + generate + + + ${project.basedir}/docs/api/swagger/openapi.yml + org.onap.cps.rest.controller + org.onap.cps.rest.model + org.onap.cps.rest.controller + jaxrs-cxf + true + + src/gen/java + java8 + jersey2 + true + + + + + org.apache.maven.plugins @@ -107,7 +149,9 @@ ${swagger-ui.version} - ${project.build.directory}/swagger-ui-${swagger-ui.version} + + ${project.build.directory}/swagger-ui-${swagger-ui.version} + @@ -125,10 +169,13 @@ copy-resources - ${project.build.outputDirectory}/static/swagger-ui + ${project.build.outputDirectory}/static/swagger-ui + - ${project.build.directory}/swagger-ui-${swagger-ui.version}/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/ + + ${project.build.directory}/swagger-ui-${swagger-ui.version}/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/ + **/*.gz 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 @@ http://www.onap.org/ - - 11 - 2.3.3.RELEASE - 3.1.0 - 5.0.6 - 2.1.4 - 3.0.6 - 2.0-M2-groovy-3.0 - 3.1.2 - 3.2.0 - 1.5.3 - 3.35.0 - 2.10.0 - + + 11 + 2.3.3.RELEASE + 3.1.0 + 5.0.6 + 2.1.4 + 3.0.6 + 2.0-M2-groovy-3.0 + 3.0.18 + 3.0.0 + 2.2.9 + 3.1.2 + 3.2.0 + 1.5.3 + 3.35.0 + 2.10.0 + @@ -113,7 +116,7 @@ - org.codehaus.gmavenplus gmavenplus-plugin @@ -126,7 +129,7 @@ - org.apache.maven.plugins