Skip to content

Generate code from TypeSpec

Weidong Xu edited this page Nov 12, 2024 · 4 revisions

Before you Start

Java Azure SDK Design Guidelines is the overall design guideline of the data-plane SDK. Make sure you are familiar with concepts such as "Service Client" and "Packaging".

Make sure you are familiar with Git and Maven, especially the Build Lifecycle.

Generate SDK

Use SDK Automation from REST API specifications

☑️ It is recommended to configure TypeSpec package on REST API specifications. Please refer to these guidelines.

Particularly, here is a sample for tspconfig.yaml. Please make sure service-dir, package-dir, namespace (for typespec-java) is correctly configured.

  • "parameters.service-dir.default" would be sdk/<service>
  • "options.@azure-tools/typespec-java.package-dir" would be <module>

If you have your namespace reviewed and finalized as e.g. azure-resourcemanager-elasticsearch (com.azure.resourcemanager.elasticsearch), <service> would be elasticsearch, module would be azure-resourcemanager-elasticsearch.

After configuration is completed, making a draft pull request on azure-rest-api-specs repository would automatically trigger SDK generation for all configured SDKs. The automation will create new pull request on azure-sdk-for-java repository. One can fork it for further development.

Use TypeSpec defined in REST API specifications

☑️ The package structure in the azure-rest-api-specs repository should follow these guidelines.

SDK will be generated under the SDK project folder of azure-sdk-for-java.

Configuration

You can update tsp-location.yaml under SDK project folder to track the TypeSpec project.

Here is an example

You can refer to the tsp-location.yaml which describes the supported properties in the file.

Here is an example.

Generate Code

With tsp-location.yaml ready, run the following tsp-client command from project directory (i.e. your current directory is <sdk-repository-dir>/sdk/<service>/<module>) to generate the code:

tsp-client update

☑️ tsp-client can be installed globally via npm install -g @azure-tools/typespec-client-generator-cli.

Build

See Build.

Clone this wiki locally