Generate Wrapper APIs Using the CLI
The enhanced version of Blockchain App Builder includes the generateFnAPI
command, which generates wrapper APIs for all controller APIs in a chaincode project.
Usage: ochain generateFnAPI [options]
Generation of WrapperAPI package for controller functions
Options:
-h, --help Output command usage information
-D, --debug Enable debug logging
-m, --mapping <mapping> Info about functions endpoints mapping is mandatory.
-c, --config <config> Info about configuration variables is mandatory.
-a, --all <all> Generate the wrapperAPI package for entire controller functions
-p, --project <path> Path to the Ochain chaincode project to generate the WrapperAPI package. If not specified, it defaults to current directory.
ochain generateFnAPI --mapping <info object about function mapping> --config <info about the config variables> --project <Path to the Ochain chaincode project> --out <Path to the generated postman collection>
When you run the generateFnAPI
command, you are prompted whether to overwrite any previous wrapper API packages that exist in the selection location.
API Gateway limits the number of routes that can be created in a single deployment to 50. If you try to use the generateFnAPI
command to generate more than 50 wrapper APIs, you are prompted whether to create multiple gateways. Creating multiple gateways with the same deployment path prefix maintains a consistent base path across all wrapper API endpoints. If you choose not to create multiple gateways, wrapper API generation is canceled.
Command Options
- -m, --mapping <mapping>
- The mapping option defines the configuration of controller APIs, specifying the endpoint names and which controller APIs require wrapper API generation. The map is a JSON object of key/value pairs, where the key is the name of the controller API and the value is the custom endpoint to associate with that controller API.
The following example shows a mapping for chaincode that uses the extended Token Taxonomy Framework standard.
ochain generateFnAPI --mapping '{"addConversionRate":"/addConversionRateTest", "addTokenAdmin": "/addTokenAdminTest", "approveBurn": "/approveBurnTest", "createAccount": "/createAccount", "associateTokenToAccount": "/associateTokenToAccountTest", "getAllOrgAccounts": "/getAllOrgAccounts"}' --config <info about the config variables> --project <Path to the Ochain chaincode project> --out <Path to the generated postman collection>
- -c, --config <config>
- The config option is used to pass the configuration variables that are required for the wrapper API package. It is a JSON object of key/value pairs, where the key is the configuration variable name and the value is the configuration variable value. All of the configuration variables are mandatory for generating a wrapper API package. If any of the following variables are not passed to the command, wrapper API generation fails. You can edit these values after you create the wrapper API by extracting the wrapper API
.zip
file.Variable name Description compartment_ocid
The OCID of the compartment in Oracle Cloud Infrastructure (OCI). compartment_name
The name of the OCI compartment. identity_domain
The identity domain to use. blockchain_channel
The name of the Oracle Blockchain Platform channel where the chaincode is deployed. blockchain_url
The Oracle Blockchain Platform URL associated with the chaincode deployment. blockchain_chaincode
The name of the chaincode to generate wrapper APIs for. blockchain_sync
The sync value to include in the payload for API calls. blockchain_timeout
The timeout value to include in the payload for API calls. vcn_display_name
The display name of the OCI virtual cloud network. application_display_name
The display name of the OCI application. gateway_display_name
The display name of API Gateway. deployment_display_name
The display name of the deployment in API Gateway. deployment_path_prefix
The deployment path prefix in API Gateway, which specifies the path where routes are deployed. The deployment_path_prefix
variable must begin with a slash (/).ocir_repo_name
The OCI Registry repository name. The ocir_repo_name
variable must be all lowercase letters.policy_name
The name of the policy that enables controlled management and access to APIs through defined permissions for groups and compartments within the organization The following example shows a mapping for chaincode that uses the extended Token Taxonomy Framework standard.
ochain generateFnAPI -m '{"addConversionRate":"/addConversionRateTest", "addTokenAdmin": "/addTokenAdminTest", "approveBurn": "/approveBurnTest", "createAccount": "/createAccount", "associateTokenToAccount": "/associateTokenToAccountTest", "getAllOrgAccounts": "/getAllOrgAccounts"}' -c '{"compartment_ocid": "compartment_ocid value", "compartment_name": "compartment_name value", "identity_domain" : "OracleIdentityCloudService", "blockchain_channel": "default", "blockchain_url": "blockchain_url value", "blockchain_chaincode": "blockchain_chaincode value", "blockchain_sync": true, "blockchain_timeout": 6000, "vcn_display_name": "vcn_display_name value", "application_display_name": "application_display_name value", "gateway_display_name": "gateway_display_name value", "deployment_display_name": "deployment_display_name value", "deployment_path_prefix": "deployment_path_prefix value", "ocir_repo_name": "ocir_repo_name value", "policy_name": "policy_name value"}'
- -a, --all <all>
- The all option generates wrapper API for all controller APIs that are defined in the chaincode. If
true
, this option overrides the mapping option. Every wrapper API is assigned a default endpoint, which corresponds to the API name. If you specify the all option, you must still provide an empty JSON object ({}) for the mapping option.The following example shows a mapping for chaincode that uses the extended Token Taxonomy Framework standard.
ochain generateFnAPI -m '{}' -c '{"compartment_ocid": "compartment_ocid value", "compartment_name": "compartment_name value", "identity_domain" : "OracleIdentityCloudService", "blockchain_channel": "default", "blockchain_url": "blockchain_url value", "blockchain_chaincode": "blockchain_chaincode value", "blockchain_sync": true, "blockchain_timeout": 6000, "vcn_display_name": "vcn_display_name value", "application_display_name": "application_display_name value", "gateway_display_name": "gateway_display_name value", "deployment_display_name": "deployment_display_name value", "deployment_path_prefix": "deployment_path_prefix value", "ocir_repo_name": "ocir_repo_name value", "policy_name": "policy_name value"}' -a true