Create Action Project for simple CAP Service in Lobby
- to modify the generated OpenAPI specification of a CAP Service
- to create an action project based on the API specification
- to test API using a BTP destination
- to release and publish the action project to be consumed in a process of SAP Build Process Automation
Prerequisites
- SAP BTP Free Trial Account OR
SAP BTP Free Tier Account with the SAP Build Process Automation enabled
- Step 1
The OpenAPI spec was generated as part of the previous tutorial Create simple CAP Service with Node.js using the SAP Business Application Studio. This definition will be used to create the Action Project in SAP Build and needs some manual changes.
-
In the subfolder
docs
folder, open the filesap_build_cap_sample_library.openapi3.json
-
Update the following paths definitions, add the missing quotes (just replace the lines in the generated file)
JSONCopy"/toInteger(value='{value}')": {
JSONCopy"/toNumber(value='{value}')": {
JSONCopy"/addQuotes(value='{value}')": {
-
Update the paths and schema definition for
getListOfTodos
(just replace the lines in the generated file)The output for this action must be set as required, this needs two modifications
-
remove allOf for the paths definition
JSONCopy"/getListOfTodos()": { "get": { "summary": "get list of Todos", "tags": [ "Service Operations" ], "parameters": [], "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/sap_build_cap_sample_library.DataListArray" } } } }, "4XX": {
-
add required: true for components/schemas schema definition of DataListArray
JSONCopy"sap_build_cap_sample_library.DataListArray": { "title": "DataListArray", "type": "object", "properties": { "responseArray": { "type": "array", "required": true, "items": { "$ref": "#/components/schemas/sap_build_cap_sample_library.DataList" }
-
-
Update the responses > schema definition
To get correct output information for the actions just replace the lines in the generated file in each of the following sections
-
/toInteger(value='{value}'): {
JSONCopy"200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/sap_build_cap_sample_library.DataInteger" } } } }, "4XX": {
-
/toNumber(value='{value}'): {
JSONCopy"200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/sap_build_cap_sample_library.DataNumber" } } } }, "4XX": {
-
/toStr(value={value}): {
and -
/addQuotes(value='{value}'): {
and -
/listToString: {
JSONCopy"200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/sap_build_cap_sample_library.DataString" } } } }, "4XX": {
-
-
Select the file content Ctrl-a in the editor and copy to your clipboard Ctrl-c
-
Create a new file called demo.json in a local folder of your desktop
-
Open the file, paste the content and save the file. You will use the file later to create the Action Project.
Here a screenshot with parts how the file will look like:
Log in to complete tutorial -
- Step 2
From the Lobby of SAP Build click Create
In the popup, choose Build an Automated Process and then select type Actions.
Specify the name
CAP Sample Actions
and upload the API spec demo.json, click CreateOnce the action project is created, the action editor will automatically open. In the popup select all actions from the list, click Add
Your Action Project will contain the actions for the CAP service
Log in to complete tutorial - Step 3
You can test the execution of your action in the Action Editor.
Select
listToString
from the list, the action has input parametersSelect Tab Test
Choose Destination Demo_CAP_Sample_Library
enter id
1
enter title
task1
enter field
id
Click Test
In the Test you can specify only one value for a list. In the Response View you can see that the values are converted to a string (with more than one value they will be comma separated). You can also try title as field and check the result.
Select
get list of Todos
from the list, click Output tab to check that the array is marked as required withred asterix
Select Test tab and click Test
You can test the other actions (optional)
Select toInteger from the list, enter value
10
and click TestSelect toNumber from the list, enter value
10.9
and click TestSelect adQuotes from the list, enter value
abc
and click Test
- Step 4
To be able to use the Actions in a Process, you have to release and publish the Action Project.
Click Release
Enter release information, click Release
Click Publish to Library
Log in to complete tutorial