Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


create dataspace v1create dataspace v2
URI

POST:

http://localhost:8883/cps/api/v1/dataspaces?dataspace-name=testDataspace

POST:

http://localhost:8883/cps/api/v2/dataspaces?dataspace-name=testDataspace

Response 

HTTP Code : 201

content-type: plain/text

response body : testDataspace

HTTP Code : 201

response body : NO CONTENT 

Note : all Once we migrate to v2, other existing APIs will be supported in 'v2' also.v1 and v2 without any impact. 


Code changes to support v2 :  

S.No

changes

1.

change cps-rest/docs/openapi.yaml file 

  /v1/dataspaces:
    $ref: 'cpsAdmin.yml#/dataspaces'

  /v2/dataspaces:
    $ref: 'cpsAdminV2.yml#/dataspaces'

Note : since same URL support more then one actions (CRUD), we need to create two different URL in yml file. if all the CRUD operations to be supported in v2, we can make changes in yml file as below :

 /{version:v[1-2]}/dataspaces/{dataspace-name}/anchors/{anchor-name}/node:
    $ref: 'cpsData.yml#/nodeByDataspaceAndAnchor'

2. 

create cpsAdminV2.yml file and add POST APIs(as below) which need to be changed . 


dataspaces:
  post:
    description: Create a new dataspace
    tags:
      - cps-admin
    summary: Create a dataspace
    operationId: createDataspaceV2
    parameters:
      - $ref: 'components.yml#/components/parameters/dataspaceNameInQuery'
    responses:
      '201':
        $ref: 'components.yml#/components/responses/CreatedV2'
      '400':
        $ref: 'components.yml#/components/responses/BadRequest'
      '401':
        $ref: 'components.yml#/components/responses/Unauthorized'
      '403':
        $ref: 'components.yml#/components/responses/Forbidden'
      '409':

3.

add CreateV2 in components.yml as below:

    CreatedV2:
      description: Created withoud response body

4. 

autogenerated code in CpsAdminApi.java


   @RequestMapping(value = "/v2/dataspaces",
        produces = { "application/json" },
        method = RequestMethod.POST)
    ResponseEntity<Void> createDataspaceV2(@NotNull @Parameter(in = ParameterIn.QUERY, description = "dataspace-name" ,required=true,schema=@Schema()) @Valid @RequestParam(value = "dataspace-name", required = true) String dataspaceName);

5. 

Implement autogenerated method "createDataspaceV2" in AdminRestController.java

    @Override
    public ResponseEntity<Void> createDataspaceV2(@NotNull @Valid final String dataspaceName) {
        cpsAdminService.createDataspace(dataspaceName);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

...

Open Issues :

  1. Duplicate code is expected for few operations where one of the CRUD function should behave differently in different versions. we need to further investigate on how to overcome this problem