Implementing a REST Service Using a JSON File with "anyOf" Keyword
This REST sample shows how to use the OpenAPISpecification 3.0 JSON file with "anyOf" keyword to create a RESTful service for adding pets data from a pet store.
The sample uses the following HTTP POST method for the Pets REST resource:
- Procedure
-
In the samples directory, select binding > rest > anyOf and double-click tibco.bw.sample.binding.rest.anyOf. For more information, see the Accessing Samples section.
-
In the Project Explorer, expand the tibco.bw.sample.binding.rest.anyOf 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.anyOf.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.anyOf.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.anyOf.application1.0[Discovery Url]: http://bwin2k16-67:7777/tibco.bw.sample.binding.rest.anyOf.application
-
Launch the Google Chrome browser and open
http://bwin2k16-67:7777/tibco.bw.sample.binding.rest.anyOf.application.The Swagger API Page displays as follows:
-
Click any of the operations, such as GET, PATCH or POST, 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-allPets
-
POST pets details
POST pets return an output similar to the following :
{"name": "Oliver","bark": true,"breed": "Shepherd","id": "CT001","age": 6}
The PetData.log file generated with the following information:
***********Output of Pets Data***********
POST having anyOf Pet→ {"anyOf_Dog":{"name":"Oliver","bark":true,"breed":"Husky"},"anyOf_Cat":{"id":"CT0014","age":4}}
**************************************************************
Understanding the Configuration
The project contains two processes, PetsService.bwp and Client.bwp.
PetsService Process: In this process, the Pets REST service performs the post operation. It adds the details of pets to the petstore and responds with the Pets details. This service is created using the Petstore_anyOf.json file. The file has Dog, Cat, and Pet objects. The Pet objects use the "anyOf '' keyword to validate against either the 'Dog' or the 'Cat' schema or both the schemas depending on the configuration provided on the Input tab of the postOut (reply) activity.
Client Process: This is a REST Client process, which uses the REST Invoke activity to call the REST Server. The request can contain a combination of properties which are valid against either one or both the Dog and Cat sub-schemas.
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.