CPS-1128 Make CPS Core API more restful
Overview
The wiki discusses upon some of the missing API's in CPS core which can be included in future releases and also suggests some changes in the current API implementation to make CPS core API's more Restful.
The second part of this wiki discusses some inconsistencies noticed with the response codes returned by CPS core API's. and how it can be improved.
CPS API that can be added/updated
Jira Ticket- CPS-1128
List of new APIs
Get all dataspaces
Get single dataspace
Get all schema sets for a dataspaces
List of existing API's that can be updated
This section discusses on existing API's that can be updated to make them more restful
Create multiple root nodes in parallel (ref. Jira- CPS-341)
URL : POST http:// IP:PORT/cps/api/v1/dataspaces/<dataspace-name>/anchors/<anchor-name>/nodes?xpath=/
Note: For get multiple nodes we will use same API for get singular node to return. Can we have new end point for getting all root nodes ‘/nodes’.
Create Dataspace should not have response body
URL : POST http://IP:PORT/cps/api/v2/dataspaces?dataspace-name=testDataspace
Create schema-set should not have response body
URL : POST http://IP:PORT/cps/api/v2/dataspaces/<dataspace-name>/schema-sets
Create an anchor should not have response body
URL : POST http://IP:PORT/cps/api/v2/dataspaces/<dataspace-name>/anchors?schema-set-name=<schema-set-name>&anchor-name=<anchor_name>
Create Node: if leaf list has only one leaf, then don’t force to use [] in request payload?
Current error message:
Only error code 500 Internal Server Error is returned.
The logs are as follows
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Node (org:onap:ccsdk:sample?revision=2020-09-15)authors is not a simple typehere authors is name of leaf-list in schema/yang resource
leaf-list authors { type string; }Sample error message:
Node (org:onap:ccsdk:sample?revision=2020-09-15)authors in schema is a leaf-list. Data received is of type list (or leaf).Note: We need to handle above error and add a leaf list if there is only one leaf in leaf-list without forcing []. Include list as it accepts data without [], so do we need the error or change leaf-list to accept without []
CPS API error responses
As per the discussion with CPS team, it was concluded that the proposal for changing the error code response for following API's is not required at the moment. This decision was made with reference to the research and decisions found at the following Epic CPS Exceptions and REST APIs HTTP Response Codes. Although an inconsistency was found with the API "Create a Node" which can be found below at point number 13. It is to be resolved in upcoming release.
Query a node
Create Schema Set
Get a Schema Set
Delete Schema
Create Anchor
Get All Anchors
Get an Anchor
Delete an Anchor
Get a Node
Delete a Node
Replace Descendants of a Node
Update a data node leaves for a given dataspace and anchor and a parent node xpath
Create Node
When an invalid json is passed (for example JSON with missing brackets) API returns 400 Bad Request without details.
When a valid json is passed with typo (for example JSON having a misspelled key) then returns 500 server error, should return 400 with response message