Implementing a REST Service Using a JSON File with "oneOf" Keyword
This REST sample shows how to use the OpenAPISpecification 3.0 JSON file with "oneOf" keyword to create a RESTful service for updating pets data from a pet store.
The sample uses the HTTP PATCH method for the Pets REST resource.
- Procedure
-
In the samples directory, select binding > rest > oneOf and double-click tibco.bw.sample.binding.rest.oneOf. For more information, see the Accessing Samples section.
-
In the Project Explorer, expand the tibco.bw.sample.binding.rest.oneOf project.
-
Set the default application profile to match the operating system you are using. For more information, see Setting the Default Application Profile.
-
Fully expand the Processes directory and double-click PetsService.bwp.
-
Click Run > Debug Configurations.
-
At the left side pane of the Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
-
Click the Applications tab and then click the Deselect All button, if you have multiple applications. Select the checkbox next to tibco.bw.sample.binding.rest.oneOf.application.
-
Click Debug. This runs the sample in the debug mode.
The console window shows engine messages similar to:
Started BW Application [tibco.bw.sample.binding.rest.oneOf.application:1.0].
The OSGI command to list REST and Swagger URLs is
lrestdoc, which lists the following discovery URL:[Application Name]: tibco.bw.sample.binding.rest.oneOf.application1.0[Discovery Url]: http://bwin2k16-67:7777/tibco.bw.sample.binding.rest.oneOf.application
-
Launch the Google Chrome browser and open
http://bwin2k16-67:7777/tibco.bw.sample.binding.rest.oneOf.application.The Swagger API Page displays as follows:
-
Click the PATCH operation displayed on the web page.
-
After completing the operations on the page, in TIBCO Business Studio for BusinessWorks, click the Terminate icon (
) to stop the application.
Pets
| • | PATCH pets details |
PATCH pets return an output similar to the following
{"name":"Rusty","bark":true,"breed":"Shepherd"}
The PetData.log file generated with the following information:
***********Output of Pets Data***********PATCH Pet having oneOf-->
{"oneOf_Dog":{"name":"Rusty","bark":true,"breed":"Shepherd"}}**************************************************************
***********Output of Pets Data***********PATCH Pet having oneOf-->
{"oneOf_Cat":{"id":"CT011","hunts":false,"age":3}}**************************************************************
Understanding the Configuration
The project contains two processes, PetsService.bwp and Client.bwp.
PetsService Process: In this process, the Pets REST service performs the patch operation. It updates the details of the pet to the petstore and retrieves the dog details from the petstore. This service is created using the Petstore_oneOf.json file. The file has Dog, Cat, and Pet objects. The Pet objects use the "oneOf '' keyword to validate against either the 'Dog' or the 'Cat' schema depending on the condition provided on the Input tab of the patchOut (reply) activity.
Client Process:This is a REST Client process, which uses the REST Invoke activity to call the REST Server.
Process contains a ForEach loop to demonstrate that the change in the mapping to input schemas (Either Dog Or Cat) will affect the response received from the server.
The first iteration of the loop will send the input which is of Type Dog. The second iteration of the loop will send the input of type Cat.
Troubleshooting
-
If you do not see the REST Swagger API page, verify whether the application has started.
-
If you see any problem markers in the project, clean the project by clicking Project > Clean or try switching to a clean new workspace.