| copyright |
|
||
|---|---|---|---|
| lastupdated | 2017-11-02 |
{:new_window: target="_blank"} {:shortdesc: .shortdesc} {:screen: .screen} {:codeblock: .codeblock} {:pre: .pre}
{: #sdk-cli}
The {{site.data.keyword.IBM}} SDK Generator plug-in can be installed in the {{site.data.keyword.Bluemix_notm}} CLI .
As a developer on {{site.data.keyword.Bluemix_notm}}, you can use this plug-in to generate SDKs from your Open API Specification compliant REST API definition. As you make changes to your REST API definition, you can use this plug-in to regenerate only the SDK instead of regenerating the entire project.
You can also see if your Cloud Foundry apps in a given space have REST API definitions that are valid for SDK generation. Finally, you can use the {{site.data.keyword.IBM_notm}} SDK Generator plug-in to validate any REST API definitions to ensure that they comply with the SDK generator requirements.
This {{site.data.keyword.IBM_notm}} SDK Generator plug-in allows you to easily integrate your backend services to your app with a generated SDK. When a change to a REST API occurs, you can re-generate the SDK and replace the old one for a seamless SDK upgrade. You can also integrate the CLI into a devops pipeline and ensure that the SDK is always consistent with the API spec each time the app is built.
The REST API definition must be valid and either hosted on a live server endpoint or a local file on your system. If the REST API definition is hosted, the relative URL must be defined in the OPENAPI_SPEC environment variable.
{: #prereqs}
Ensure that you satisfy the following requirements.
- You have a {{site.data.keyword.Bluemix_notm}}
account
- A valid API definition that conforms to the Open API
specification
{: #installation}
-
bx plugin install sdk-gen{: codeblock}
{: #commands}
Use the following commands to generate an SDK, validate Open API definition files, or list Cloud Foundry apps.
{: #gen}
Use bx sdk generate [arguments...] [command options].
{: #gen-args}
APP_NAME- the name of the Cloud Foundry app in your current spaceOPENAPI_DOC_LOCATION- a URL or a relative file path to the raw REST API definition JSON or YamlGENERATED_SDK_NAME(optional) - the name of the generated SDK
{: #gen-options}
PLATFORM(required)--android- generate an Android SDK--ios- generate an iOS Swift SDK--swift- generate a Swift server SDK--js- generate a JavaScript SDK
LOCATION(required) - specifies the type forOPENAPI_DOC_LOCATION-r- remote URL-f- file-a- app that runs on {{site.data.keyword.Bluemix_notm}}-l- localhost URL
--output "YOUR_RELATIVE_PATH"(optional) - places the generated SDK in the directory that is specified byYOUR_RELATIVE_PATH(overwrites if existing SDK is present)--unzip(optional) - extracts the generated SDK (overwrites if existing SDK artifacts are present)
{: #gen-usage}
To generate an SDK from a Cloud Foundry app that is running in {{site.data.keyword.Bluemix_notm}}, you can use the app's name as a parameter to the CLI. The following command uses the app's name as the SDK_Name.
bx sdk generate [APP_NAME] [LOCATION] [PLATFORM]
{: codeblock}
To generate an SDK from a URL to an Open API definition file or a local JSON or Yaml file, use the following command.
bx sdk generate [OPENAPI_DOC_LOCATION] [SDK_Name] [LOCATION] [PLATFORM]
{: codeblock}
{: #validating}
Use bx sdk validate [argument].
{: #val-args}
APP_NAME- the name of the Cloud Foundry app in your current spaceOPENAPI_DOC_LOCATION- a URL or a relative file path to the raw REST API definition JSON or Yaml
{: #val-usage}
To validate a Cloud Foundry app's API spec that is running in {{site.data.keyword.Bluemix_notm}}, you can use the app's name as a parameter to the CLI.
bx sdk validate [APP_NAME] [LOCATION]
{: codeblock}
To validate an SDK from the URL to an API spec document or a local JSON or Yaml file, use the following command.
bx sdk validate [OPENAPI_DOC_LOCATION] [LOCATION]
{: codeblock}
{: #list-apps}
Use bx sdk list [argument] [option] to list apps and validate API specs. You must have the OPENAPI_SPEC environment variable set to relative url path hosting your spec.
{: #list-args}
SPACE_NAME(optional) - the name of the Cloud Foundry space within your current organization that you want to search for apps. If not provided, the current space is searched.
{: #list-options}
--url(optional) - to display a fully formed URL to the Open API definition for each app in the list
{: #list-usage}
To list apps in the current space, use the following command.
bx sdk list
{: codeblock}
To list apps in the current space and display the API spec URL, use the following command.
bx sdk list --url
{: codeblock}
To list apps in a specific space, use the following command.
bx sdk list [SPACE_NAME]
{: codeblock}
To list apps in a specific space and display the API spec URL, use the following command.
bx sdk list [SPACE_NAME] --url
{: codeblock}