In this exercise, you will import the OpenApi definition from an existing API and explore the ActiveDocs generated by Red Hat 3scale API Management.
Outcomes
You should be able to:
Import the OpenApi definition of an API into 3scale API Management.
Use ActiveDocs in the Admin Portal to explore the API.
Update the Documentation template in Admin Portal to show all the ActiveDocs in the Developer Portal.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command deploys a pet shelter API to the Red Hat OpenShift Container Platform (RHOCP) cluster.
[student@workstation ~]$ lab start portal-openapi
Procedure 5.3. Instructions
Add the backend URL to the OpenApi definition. This is the pet shelter API internal URL accessible from within the RHOCP cluster.
Examine the ~/DO240/labs/portal-openapi/openapi-definition.yaml file, and search for the CHANGE_ME URL value in the servers section.
Replace the CHANGE_ME URL value with the cluster API URL, http://petshelter-api.portal-openapi.svc.cluster.local
Import the openapi-definition.yaml OpenApi definition.
Execute the 3scale_wrapper.sh script to import the OpenApi definition.
Name the product resulting from the import with portal_openapi by providing the --target_system_name=portal_openapi argument.
The 3scale_wrapper.sh script mounts the last parameter as a Podman volume file to run 3scale Toolbox CLI with Podman.
[student@workstation ~]$ \
~/DO240/labs/portal-openapi/3scale_wrapper.sh import openapi \
--target_system_name=portal_openapi \
--destination=3scale-tenant \
DO240/labs/portal-openapi/openapi-definition.yaml
{
"code": "E_3SCALE",
"message": "User key must be provided by --default-credentials-userkey optional param",
"class": "ThreeScaleToolbox::Error"
}
Created service id: 3, name: Pet Shelter
Service proxy updated
destroying all mapping rules
Created PUT /pet$ endpoint
Created POST /pet$ endpoint
Created GET /pet/findByStatus$ endpoint
Created GET /pet/{petId}$ endpoint
Created DELETE /pet/{petId}$ endpointYou can ignore the error message.
You can add the --default-credentials-userkey=anonymous_api_key option to allow for unauthenticated endpoints. This creates an Anonymous Access policy with the anonymous_api_key value.
Use the 3scale Toolbox CLI proxy-config command to get the portal_openapi product's proxy configuration, and verify that the previous step creates a backend with the correct URL.
[student@workstation ~]$ 3scale proxy-config show \
3scale-tenant portal_openapi sandbox -o json \
| jq -r '.content.proxy.api_backend'
http://petshelter-api.portal-openapi.svc.cluster.local:80Create an application plan and an application.
Create an application plan called basic_plan by using the 3scale Toolbox CLI from the command line.
[student@workstation ~]$ 3scale application-plan create \
3scale-tenant portal_openapi basic_plan
Created application plan id: 13. Default: false; Disabled: falseCreate an application on the default john account called shelter-app, and assign it the basic_plan application plan.
[student@workstation ~]$ 3scale application create \
3scale-tenant john portal_openapi basic_plan shelter-app
Created application id: 7Configure the portal_openapi product to allow access from the Admin Portal and the Developer Portal.
Navigate to → from the portal_openapi product page.
Then update the policy chain by adding the CORS Request Handling policy and placing it before the 3scale APIcast policy in the policy chain.
Configure the CORS policy by setting:
allow_origin: (3scale-admin|3scale).apps.ocp4.example.com
The syntax between parentheses allows our API to be called from:
The Admin Portal domain: 3scale-admin.apps.ocp4.example.com
The Developer Portal domain: 3scale.apps.ocp4.example.com
Then click and then .
Promote the portal_openapi configuration first to staging and then to production.
Verify that you can reach the petshelter-api RHOCP service by using the ActiveDocs in the Admin Portal.
Click from the side menu in the portal_openapi product.
Then click to go to the interactive documentation.
Click to open the endpoint documentation.
To test the call click , then:
Select the available value for the status parameter.
Click the drop-down menu and select the shelter-app to automatically fill the user_key parameter.
Click to send the request.
The response shows in the 200 code under the section.
{
"0": {
"photoUrls": [
"photo_1_url",
"photo_2_url"
],
"name": "spotty",
"id": 0,
"category": {
"name": "dogs",
"id": 6
},
...output omitted...Update the Developer Portal Documentation page to show all the ActiveDocs in the tenant.
Open the ~/DO240/labs/portal-openapi/dev-portal-docs.liquid file to copy its content.
Navigate to the page. Then click and click to edit the documentation page.
Scroll to the section and replace the default template by pasting the contents from the dev-portal-docs.liquid file.
Then click and .
Use the 3scale Toolbox CLI to retrieve the user_key for the shelter-app application.
[student@workstation ~]$ 3scale application list \
--service=portal_openapi 3scale-tenant -o json \
| jq -r '.[] | select(.name == "shelter-app")|.user_key'
7acb0243fdc7a30882f39dbf95261ab7Navigate to https://3scale.apps.ocp4.example.com/docs to test the ActiveDocs from the Developer Portal.
Scroll to the portal_openapi documentation. Then click to open the endpoint documentation.
To test the call click , then:
Select the available value for the status parameter.
Paste the user_key from the previous step to fill the user_key parameter.
Click to send the request.
The response shows in the 200 code under the section.
This concludes the guided exercise.