Refactoring of CPS Delta APIs 66/138266/6
authorArpit Singh <as00745003@techmahindra.com>
Tue, 9 Jul 2024 11:44:02 +0000 (17:14 +0530)
committerArpit Singh <as00745003@techmahindra.com>
Wed, 7 Aug 2024 04:30:28 +0000 (10:00 +0530)
Refactoring of CPS delta APIs from two separate endpoints to a single endpoint.
  - GET: /v2/dataspaces/{dataspace-name}/anchors/{anchor-name}/deltaAnchors
  - POST: /v2/dataspaces/{dataspace-name}/anchors/{anchor-name}/deltaByPayload
To new endpoint can perform two operatios as follows:
  - GET: /v2/dataspaces/{dataspace-name}/anchors/{source-anchor-name}/delta
  - POST: /v2/dataspaces/{dataspace-name}/anchors/{source-anchor-name}/delta

Note: this patch only addresses the issue around refactoring of Delta
endpoint to a singular well defined endpoint. A separate patch will
be created to refactor the entire Delta feature out of CPS Data,
into a separate interface namely CPS Delta

Issue-ID: CPS-2310
Change-Id: Ic62c8308cf368b4378235597a11c476809a150b8
Signed-off-by: Arpit Singh <as00745003@techmahindra.com>
cps-rest/docs/openapi/components.yml
cps-rest/docs/openapi/cpsDataV2.yml
cps-rest/docs/openapi/openapi.yml
cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy

index a2587eb..850ecb6 100644 (file)
@@ -183,6 +183,14 @@ components:
       schema:
         type: string
         example: my-anchor
+    sourceAnchorNameInPath:
+      name: source-anchor-name
+      in: path
+      description: source-anchor-name
+      required: true
+      schema:
+        type: string
+        example: my-anchor
     schemaSetNameInQuery:
       name: schema-set-name
       in: query
index a1433ba..d5a8ef3 100644 (file)
@@ -46,7 +46,7 @@ nodeByDataspaceAndAnchor:
         $ref: 'components.yml#/components/responses/InternalServerError'
     x-codegen-request-body-name: xpath
 
-deltaByDataspaceAndAnchors:
+delta:
   get:
     description: Get delta between two anchors within a given dataspace
     tags:
@@ -55,7 +55,7 @@ deltaByDataspaceAndAnchors:
     operationId: getDeltaByDataspaceAndAnchors
     parameters:
       - $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
-      - $ref: 'components.yml#/components/parameters/anchorNameInPath'
+      - $ref: 'components.yml#/components/parameters/sourceAnchorNameInPath'
       - $ref: 'components.yml#/components/parameters/targetAnchorNameInQuery'
       - $ref: 'components.yml#/components/parameters/xpathInQuery'
       - $ref: 'components.yml#/components/parameters/descendantsInQuery'
@@ -76,8 +76,6 @@ deltaByDataspaceAndAnchors:
       '500':
         $ref: 'components.yml#/components/responses/InternalServerError'
     x-codegen-request-body-name: xpath
-
-deltaByDataspaceAnchorAndPayload:
   post:
     description: Get delta between an anchor in a dataspace and JSON payload
     tags:
@@ -86,7 +84,7 @@ deltaByDataspaceAnchorAndPayload:
     operationId: getDeltaByDataspaceAnchorAndPayload
     parameters:
       - $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
-      - $ref: 'components.yml#/components/parameters/anchorNameInPath'
+      - $ref: 'components.yml#/components/parameters/sourceAnchorNameInPath'
       - $ref: 'components.yml#/components/parameters/xpathInQuery'
     requestBody:
       content:
index ab841b2..19494fc 100644 (file)
@@ -100,11 +100,8 @@ paths:
   /{apiVersion}/dataspaces/{dataspace-name}/anchors/{anchor-name}/list-nodes:
     $ref: 'cpsData.yml#/listElementByDataspaceAndAnchor'
 
-  /v2/dataspaces/{dataspace-name}/anchors/{anchor-name}/deltaAnchors:
-    $ref: 'cpsDataV2.yml#/deltaByDataspaceAndAnchors'
-
-  /v2/dataspaces/{dataspace-name}/anchors/{anchor-name}/deltaPayload:
-    $ref: 'cpsDataV2.yml#/deltaByDataspaceAnchorAndPayload'
+  /v2/dataspaces/{dataspace-name}/anchors/{source-anchor-name}/delta:
+    $ref: 'cpsDataV2.yml#/delta'
 
   /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes/query:
     $ref: 'cpsQueryV1Deprecated.yml#/nodesByDataspaceAndAnchorAndCpsPath'
index d8ab0d1..d696af2 100755 (executable)
@@ -352,7 +352,7 @@ class DataRestControllerSpec extends Specification {
         given: 'the service returns a list containing delta reports'
             def deltaReports = new DeltaReportBuilder().actionUpdate().withXpath('some xpath').withSourceData('some key': 'some value').withTargetData('some key': 'some value').build()
             def xpath = 'some xpath'
-            def endpoint = "$dataNodeBaseEndpointV2/anchors/sourceAnchor/deltaAnchors"
+            def endpoint = "$dataNodeBaseEndpointV2/anchors/sourceAnchor/delta"
             mockCpsDataService.getDeltaByDataspaceAndAnchors(dataspaceName, 'sourceAnchor', 'targetAnchor', xpath, OMIT_DESCENDANTS) >> [deltaReports]
         when: 'get delta request is performed using REST API'
             def response =
@@ -370,7 +370,7 @@ class DataRestControllerSpec extends Specification {
         given: 'sample delta report, xpath, yang model file and json payload'
             def deltaReports = new DeltaReportBuilder().actionAdd().withXpath('some xpath').build()
             def xpath = 'some xpath'
-            def endpoint = "$dataNodeBaseEndpointV2/anchors/$anchorName/deltaPayload"
+            def endpoint = "$dataNodeBaseEndpointV2/anchors/$anchorName/delta"
         and: 'the service layer returns a list containing delta reports'
             mockCpsDataService.getDeltaByDataspaceAnchorAndPayload(dataspaceName, anchorName, xpath, ['filename.yang':'content'], expectedJsonData, INCLUDE_ALL_DESCENDANTS) >> [deltaReports]
         when: 'get delta request is performed using REST API'
@@ -391,7 +391,7 @@ class DataRestControllerSpec extends Specification {
         given: 'sample delta report, xpath, and json payload'
             def deltaReports = new DeltaReportBuilder().actionRemove().withXpath('some xpath').build()
             def xpath = 'some xpath'
-            def endpoint = "$dataNodeBaseEndpointV2/anchors/$anchorName/deltaPayload"
+            def endpoint = "$dataNodeBaseEndpointV2/anchors/$anchorName/delta"
         and: 'the service layer returns a list containing delta reports'
             mockCpsDataService.getDeltaByDataspaceAnchorAndPayload(dataspaceName, anchorName, xpath, [:], expectedJsonData, INCLUDE_ALL_DESCENDANTS) >> [deltaReports]
         when: 'get delta request is performed using REST API'