### Example: Versioning with version-status output files Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest/README.md Example output file names demonstrating versioning with status (stable/preview). ```plaintext arm-folder/AzureService/stable/2020-01-01.yaml arm-folder/AzureService/preview/2020-01-01.yaml ``` -------------------------------- ### Custom Provisioning State Example Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md Example of extending the standard ResourceProvisioningState with custom states like 'starting' and 'stopping'. ```typespec union FooProvisioningState { ResourceProvisioningState, starting: "starting", started: "started", stopping: "stopping", stopped: "stopped", } ``` -------------------------------- ### Example: Multiple services with versioning output files Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest/README.md Example output file names for multiple services with versioning. ```plaintext openapi.Org1.Service1.v1.yaml openapi.Org1.Service1.v2.yaml openapi.Org1.Service2.v1.0.yaml openapi.Org1.Service2.v1.1.yaml ``` -------------------------------- ### Install Dependencies Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/migrate-swagger/01-get-started.md Run this command at the root of the repository to install necessary project dependencies. ```shell npm install ``` -------------------------------- ### Example: Single service with versioning output files Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest/README.md Example output file names for a single service with versioning. ```plaintext openapi.v1.yaml openapi.v2.yaml ``` -------------------------------- ### Install @azure-tools/typespec-client-generator-core Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/README.md Install the library using npm. ```bash npm install @azure-tools/typespec-client-generator-core ``` -------------------------------- ### Example: Multiple services no versioning output files Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest/README.md Example output file names for multiple services without versioning. ```plaintext openapi.Org1.Service1.yaml openapi.Org1.Service2.yaml ``` -------------------------------- ### Start Local Development Server Source: https://github.com/azure/typespec-azure/blob/main/website/README.md Use this command to start a local development server for live previewing changes. The server typically runs at `localhost:4321`. ```bash pnpm dev ``` ```bash pnpm start ``` -------------------------------- ### Rename Example Version Folder Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Versioning/02-preview-after-preview.md Update the directory name for the latest preview examples to match the new preview version. ```bash > mv examples/2025-12-01-preview examples/2026-01-01-preview ``` -------------------------------- ### Start Mock API Server with pnpm Source: https://github.com/azure/typespec-azure/blob/main/packages/azure-http-specs/README.md Use this command to start the mock API server when writing mock APIs. ```bash pnpm run serve ``` -------------------------------- ### Install @azure-tools/typespec-azure-portal-core Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-azure-portal-core/README.md Install the TypeSpec Azure Portal Core library using npm. ```bash npm install @azure-tools/typespec-azure-portal-core ``` -------------------------------- ### Rename Example Directory Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Versioning/03-stable-after-preview.md Use this command to rename the directory of your preview examples to match the new stable version. ```bash > mv examples/2025-10-01-preview examples/2026-01-01 ``` -------------------------------- ### Install TypeSpec Project Dependencies Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/getstarted/createproject.md After creating a new project, run this command to install the necessary dependencies. Use `npm ci` if your project is within the `azure-rest-api-specs` repository, otherwise use `tsp install`. ```bash tsp install ``` -------------------------------- ### Example: Initialize tsp-client Generation Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate with tsp-client/local_spec_quickstart.md An example of initializing `tsp-client` generation, pointing to a specific local TypeSpec project within the `azure-rest-api-specs` repository. ```bash azure-sdk-for-python > tsp-client init -c ../azure-rest-api-specs/specification/contosowidgetmanager/Contoso.WidgetManager/ ``` -------------------------------- ### Client constructor and get method signatures Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/04method.mdx Demonstrates the client constructor and get method signatures across different languages when the subscription ID is a client parameter. ```python class ContosoProviderHubClient: def __init__(self, credential, **kwargs): ... def get(self, subscription_id: str, extended_zone_name: str, **kwargs) -> MyModel: ... ``` ```csharp // Main client with subscriptionId as client parameter public partial class ContosoProviderHubClient { public ContosoProviderHubClient(TokenCredential credential) { ... } public virtual Response Get(string subscriptionId, string extendedZoneName, CancellationToken cancellationToken = default) { ... } } ``` ```typescript export class ContosoProviderHubClient { constructor(credential: TokenCredential) { ... } async get(subscriptionId: string, extendedZoneName: string): Promise { ... } } ``` ```java public final class ContosoProviderHubClient { public ContosoProviderHubClient(TokenCredential credential) { ... } public MyModel get(String subscriptionId, String extendedZoneName) { ... } } ``` ```go // NOT_SUPPORTED ``` -------------------------------- ### Example: Single service no versioning output file Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest/README.md Example of an output file name for a single service without versioning. ```plaintext openapi.yaml ``` -------------------------------- ### Example KeyVault Keys metadata (YAML) Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-metadata/README.md This is an example of the structured metadata generated by the emitter for KeyVault Keys, in YAML format. ```yaml emitterVersion: 0.1.0 generatedAt: 2026-01-15T23:14:08.554Z typespec: namespace: KeyVault documentation: The key vault client performs cryptographic key operations and vault operations against the Key Vault service. type: data languages: python: emitterName: "@azure-tools/typespec-python" packageName: azure-keyvault-keys namespace: azure.keyvault.keys outputDir: "{output-dir}/sdk/keyvault/azure-keyvault-keys" flavor: azure serviceDir: sdk/keyvault java: emitterName: "@azure-tools/typespec-java" packageName: "com.azure:azure-security-keyvault-keys" namespace: com.azure.security.keyvault.keys outputDir: "{output-dir}/sdk/keyvault/azure-security-keyvault-keys" flavor: azure serviceDir: sdk/keyvault typescript: emitterName: "@azure-tools/typespec-ts" packageName: "@azure/keyvault-keys" namespace: "@azure/keyvault-keys" outputDir: "{output-dir}/sdk/keyvault/keyvault-keys" flavor: azure serviceDir: sdk/keyvault go: emitterName: "@azure-tools/typespec-go" packageName: sdk/security/keyvault/azkeys namespace: sdk/security/keyvault/azkeys outputDir: "{output-dir}/sdk/security/keyvault/azkeys" serviceDir: sdk/security/keyvault rust: emitterName: "@azure-tools/typespec-rust" packageName: azure_security_keyvault_keys namespace: azure_security_keyvault_keys outputDir: "{output-dir}/sdk/keyvault/azure_security_keyvault_keys" serviceDir: sdk/keyvault sourceConfigPath: C:/repos/azure-rest-api-specs/specification/keyvault/Security.KeyVault.Keys/tspconfig.yaml ``` -------------------------------- ### Install Azure Core in a Library Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-core/reference/index.mdx Use this command to install the Azure Core library as a peer dependency in your library. ```bash npm install --save-peer @azure-tools/typespec-azure-core ``` -------------------------------- ### Client Initialization and Usage Sample Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx This sample demonstrates how to initialize various Azure SDK clients and call their methods. It covers common operations like Info, Close, Open, History, Feed, and Pet. ```go petStoreClient := NewPetStoreClient() petStoreClient.Info(context.Background(), &PetStoreClientInfoOptions{}) petStoreActionsClient := NewPetStoreActionsClient() petStoreActionsClient.Close(context.Background(), &PetStoreActionsClientCloseOptions{}) petStoreActionsClient.Open(context.Background(), &PetStoreActionsClientOpenOptions{}) petStoreBillingsClient := NewPetStoreBillingsClient() petStoreBillingsClient.History(context.Background(), &PetStoreBillingsClientHistoryOptions{}) petStorePetsClient := NewPetStorePetsClient() petStorePetsClient.Info(context.Background(), &PetStorePetsClientInfoOptions{}) petStorePetsActionsClient := NewPetStorePetsActionsClient() petStorePetsActionsClient.Feed(context.Background(), &PetStorePetsActionsClientFeedOptions{}) petStorePetsActionsClient.Pet(context.Background(), &PetStorePetsActionsClientPetOptions{}) ``` -------------------------------- ### Force npm install for private build Source: https://github.com/azure/typespec-azure/blob/main/CONTRIBUTING.md Adjust the GitHub Actions setup to force npm installation, which is necessary when using private builds of packages. ```diff - - script: npm ci + - script: npm i --no-package-lock --force ``` -------------------------------- ### TypeScript Client API Definition Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/10versioning.mdx Defines known versions for a TypeScript client and an example of a 'get' operation signature. ```typescript export enum KnownVersions { V20231101 = "2023-11-01", V20240401 = "2024-04-01", } export async function get( context: Client, options: GetOptionalParams = { requestOptions: {} }, ): Promise; ``` -------------------------------- ### Initialize Client with Sub-Client (Same Parameters) Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/design-docs/client.md Shows how to initialize a client and then obtain a sub-client that shares the same initialization parameters. ```Python client = TestClient(endpoint="endpoint", credential=AzureKeyCredential("key")) client.do_something() sub_client = client.sub_client() sub_client.do_something() ``` -------------------------------- ### Install Azure Portal Core as a Library Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-portal-core/reference/index.mdx Use this command to install the Azure Portal Core library as a peer dependency when building a library that utilizes it. ```bash npm install --save-peer @azure-tools/typespec-azure-portal-core ``` -------------------------------- ### Correct Model Casing Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-core/rules/casing-style.md Provides examples of correctly cased model names and properties following the TypeSpec style guide. ```tsp model Pet {} model PetFood {} ``` ```tsp model Pet { name: string; } ``` -------------------------------- ### Go Client Initialization with Custom Parameters Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Example of generated Go client structure including custom options for upload and download operations. ```go // generated storage_client.go type StorageClient struct {} func NewStorageClient() *NewStorageClient{ return &NewStorageClient{} } func (client *StorageClient) Download(ctx context.Context, options *StorageClientDownloadOptions) (StorageClientDownloadResponse, error) {} func (client *StorageClient) Upload(ctx context.Context, options *StorageClientUploadOptions) (StorageClientUploadResponse, error) {} // generated options.go type StorageClientDownloadOptions struct {} type StorageClientUploadOptions struct {} // generated response.go type StorageClientDownloadResponse struct {} type StorageClientUploadResponse struct {} // Usage Sample client := NewStorageClient() client.Download(context.Background(), &StorageClientDownloadOptions{}) client.Upload(context.Background(), &StorageClientUploadOptions{}) ``` -------------------------------- ### Java Client Initialization with Custom Parameters Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Example of Java client builder and client classes demonstrating custom parameter usage. ```java // Client builder class package storage; @ServiceClientBuilder(serviceClients = { StorageClient.class, StorageAsyncClient.class }) public final class StorageClientBuilder implements HttpTrait, ConfigurationTrait, EndpointTrait { public StorageClientBuilder(); public StorageClientBuilder blobName(String blobName); public StorageClient buildClient(); } // Client class @ServiceClient(builder = StorageClientBuilder.class) public final class StorageClient { public void upload(); public void download(); } // Usage package storage; StorageClient client = new StorageClient() .endpoint("") .blobName("myBlobName") .buildClient(); client.upload() client.download() ``` -------------------------------- ### Example Azure DevOps Pipeline with Artifact Publishing Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/rest-api-publish/buildpipelines.md A more complete Azure DevOps pipeline example that includes setting up NodeJS, installing dependencies, compiling TypeSpec, and publishing the output as a pipeline artifact. Assumes TypeSpec files are at the repository root. ```yaml trigger: - main pool: vmImage: ubuntu-latest steps: - task: NodeTool@0 inputs: versionSpec: "22.x" - script: npm install - script: npx tsp compile . - task: PublishPipelineArtifact@1 displayName: Publish TypeSpec Output Folder inputs: targetPath: "tsp-output" artifact: "tsp-output" publishLocation: "pipeline" ``` -------------------------------- ### TenantResourceOperations Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/interfaces.md Provides operations for Tenant resources, including GET, PUT, PATCH, DELETE, and ListByParent. Routes typically start at the root level. ```APIDOC ## TenantResourceOperations ### Description A composite interface for Tenant resources that include `ResourceInstanceOperations` and `ResourceListByParent`. It includes: `GET`, `PUT`, `PATCH`, `DELETE`, ListByParent operations. The routes are always start at root level: `/providers/Microsoft.XXX/... This is the most common API pattern for Tenant Resources to use. ### Template Parameters | Name | Description | | ---------- | ---------------------------------------------- | | Resource | the ArmResource that provides these operations | | Properties | RP-specific property bag for the resource | #### `get` ```typespec op Azure.ResourceManager.TenantResourceOperations.get(apiVersion: string, provider: "Microsoft.ThisWillBeReplaced"): Azure.ResourceManager.ArmResponse | Azure.ResourceManager.CommonTypes.ErrorResponse ``` #### `createOrUpdate` ```typespec op Azure.ResourceManager.TenantResourceOperations.createOrUpdate(apiVersion: string, provider: "Microsoft.ThisWillBeReplaced", resource: Resource): Azure.ResourceManager.ArmResourceUpdatedResponse | Azure.ResourceManager.ArmResourceCreatedResponse | Azure.ResourceManager.CommonTypes.ErrorResponse ``` #### `update` ```typespec op Azure.ResourceManager.TenantResourceOperations.update(apiVersion: string, provider: "Microsoft.ThisWillBeReplaced", properties: Azure.ResourceManager.Foundations.ResourceUpdateModel): Azure.ResourceManager.ArmResponse | Azure.ResourceManager.CommonTypes.ErrorResponse ``` #### `delete` ```typespec op Azure.ResourceManager.TenantResourceOperations.delete(apiVersion: string, provider: "Microsoft.ThisWillBeReplaced"): Azure.ResourceManager.ArmDeletedResponse | Azure.ResourceManager.ArmDeleteAcceptedLroResponse | Azure.ResourceManager.ArmDeletedNoContentResponse | Azure.ResourceManager.CommonTypes.ErrorResponse ``` #### `listByParent` ```typespec op Azure.ResourceManager.TenantResourceOperations.listByParent(apiVersion: string, provider: "Microsoft.ThisWillBeReplaced"): Azure.ResourceManager.ArmResponse> | Azure.ResourceManager.CommonTypes.ErrorResponse ``` ``` -------------------------------- ### Java Client Initialization and Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Provides examples for the StorageClientBuilder and StorageClient in Java, including how to build the client and use its methods. ```java // Client builder class package storage; @ServiceClientBuilder(serviceClients = { StorageClient.class, StorageAsyncClient.class }) public final class StorageClientBuilder implements HttpTrait, ConfigurationTrait, EndpointTrait { public StorageClientBuilder(); public StorageClientBuilder blob(String blob); public StorageClient buildClient(); } // Client class @ServiceClient(builder = StorageClientBuilder.class) public final class StorageClient { public void upload(); public void download(); } // Usage package storage; StorageClient client = new StorageClient() .endpoint("") .blob("myBlobName") .buildClient(); client.upload() client.download() ``` -------------------------------- ### Go Client SDK with Renamed Parameters Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/09renaming.mdx Provides the generated Go client code for the 'get' operation, featuring the renamed parameter 'resourceID'. Includes usage example. ```go // Generated client code type PetStoreNamespaceClient struct {} func NewPetStoreNamespaceClient() *PetStoreNamespaceClient { return &PetStoreNamespaceClient{} } type PetStoreNamespaceClientGetOptions struct { Filter *string } func (client *PetStoreNamespaceClient) Get(ctx context.Context, resourceID string, options *PetStoreNamespaceClientGetOptions) (PetStoreNamespaceClientGetResponse, error) { // implementation } // Usage client := NewPetStoreNamespaceClient() filter := "active" resp, err := client.Get(context.TODO(), "name", &PetStoreNamespaceClientGetOptions{ Filter: &filter, }) ``` -------------------------------- ### Java Client SDK with Renamed Parameters Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/09renaming.mdx Displays the generated Java client code for the 'get' operation, showing the renamed parameter 'resourceId'. Includes usage example. ```java // Generated client code package petstorenamespace; public final class PetStoreNamespaceClient { public Response getWithResponse(BinaryData getRequest, RequestOptions requestOptions) { // implementation } public InputModel get(String resourceId, String filter) { // implementation } } // Usage InputModel model = client.get("name", "active"); ``` -------------------------------- ### TypeScript Client SDK with Renamed Parameters Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/09renaming.mdx Presents the generated TypeScript client code for the 'get' operation, demonstrating the renamed parameter 'resourceId'. Includes usage example. ```typescript // Generated client code export interface GetOptionalParams extends OperationOptions { filter?: string; } export async function get( context: Client, resourceId: string, options: GetOptionalParams = { requestOptions: {} }, ): Promise; // Usage const result = await get(context, "name", { filter: "active" }); ``` -------------------------------- ### Rename Example Folder Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Versioning/02-preview-after-preview.md Update the example folder name to reflect the new API version. This command-line operation is necessary when introducing a new preview version. ```bash > mv examples/2025-12-01-preview examples/2026-01-01-preview ``` -------------------------------- ### Python Client Initialization and Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Demonstrates how to initialize and use the StorageClient in Python. Requires importing StorageClient from the storage library. ```python from storage import StorageClient client = StorageClient(endpoint="", blob="myBlobName", ...) client.upload() client.download() ``` -------------------------------- ### C# Client SDK with Renamed Parameters Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/09renaming.mdx Shows the generated C# client code for the 'get' operation, reflecting the renamed parameter 'resourceId'. Includes usage example. ```csharp // Generated client code namespace PetStoreNamespace { public partial class PetStoreNamespaceClient { // protocol method public virtual async Task GetAsync(string resourceId, string filter, RequestContext context) {} public virtual Response Get(string resourceId, string filter, RequestContext context) {} // convenience method public virtual async Task> GetAsync(string resourceId, string filter, CancellationToken cancellationToken = default) {} public virtual Response Get(string resourceId, string filter, CancellationToken cancellationToken = default) {} } } // Usage InputModel model = await client.GetAsync(resourceId: "name", filter: "active"); ``` -------------------------------- ### Azure_Example_Basic Source: https://github.com/azure/typespec-azure/blob/main/packages/azure-http-specs/spec-summary.md Demonstrates a basic Azure example with specified request and response structures. ```APIDOC ## POST /azure/example/basic/basic ### Description Provides a basic example for Azure services, with request and response structures mirroring a predefined JSON example. Requires the 'examples-dir' option to be set during code generation. ### Method POST ### Endpoint /azure/example/basic/basic ### Parameters #### Query Parameters - **query-param** (string) - Required - A query parameter for the request. - **api-version** (string) - Required - The API version to use. #### Header Parameters - **header-param** (string) - Required - A header parameter for the request. ### Request Body - **stringProperty** (string) - Required - A string property. - **modelProperty** (object) - Required - A model property. - **int32Property** (integer) - Required - An integer property. - **float32Property** (number) - Required - A float property. - **enumProperty** (string) - Required - An enum property. - **arrayProperty** (array) - Required - An array property. - **items** (string) - Description of array items. - **recordProperty** (object) - Required - A record property. - **record** (string) - Description of the record value. ### Request Example ```json { "stringProperty": "text", "modelProperty": { "int32Property": 1, "float32Property": 1.5, "enumProperty": "EnumValue1" }, "arrayProperty": ["item"], "recordProperty": { "record": "value" } } ``` ### Response #### Success Response (200) - **stringProperty** (string) - A string property in the response. #### Response Example ```json { "stringProperty": "text" } ``` ``` -------------------------------- ### Python Client SDK with Renamed Parameters Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/09renaming.mdx Illustrates the generated Python client code for the 'get' operation, showing the renamed parameters 'resource_id' and 'search_filter'. Includes usage example. ```python # Generated client code class PetStoreNamespaceClient: def get(self, resource_id: str, *, search_filter: Optional[str] = None, **kwargs) -> InputModel: """Get operation with renamed parameters. :param resource_id: The resource identifier (wire name: 'name') :param search_filter: Filter query (wire name: 'filter') :return: InputModel """ ... # Usage response: InputModel = client.get(resource_id="name", search_filter="active") ``` -------------------------------- ### Define TenantResourceOperations Interface Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/interfaces.md Defines a composite interface for Tenant resources, including operations like GET, PUT, PATCH, DELETE, and ListByParent. Routes for these operations start at the root level. ```typespec interface Azure.ResourceManager.TenantResourceOperations ``` -------------------------------- ### Initialize Single Client Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/design-docs/client.md Demonstrates the basic initialization of a single client with an endpoint and credentials. ```Python client = SingleClient(endpoint="endpoint", credential=AzureKeyCredential("key")) client.do_something() ``` -------------------------------- ### Initialize Client with Sub-Client (Additional Parameter) Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/design-docs/client.md Illustrates initializing a client and then obtaining a sub-client that requires an additional initialization parameter. ```Python client = TestClient(endpoint="endpoint", credential=AzureKeyCredential("key")) client.do_something() sub_client = client.sub_client(sub_name="sub") sub_client.do_something() ``` -------------------------------- ### Attach Examples with @example (Autorest) Source: https://context7.com/azure/typespec-azure/llms.txt Use the @example decorator to attach example JSON files to operations. These examples are emitted as `x-ms-examples` in Swagger output. ```typespec import "@azure-tools/typespec-autorest"; using Autorest; interface Widgets { @example("./examples/Widgets_Get.json", "Get a widget") @example("./examples/Widgets_Get_Minimal.json", "Get a widget (minimal response)") getWidget is Operations.ResourceRead; @example("./examples/Widgets_CreateOrUpdate.json", "Create or update a widget") createOrUpdateWidget is Operations.LongRunningResourceCreateOrUpdate; } ``` -------------------------------- ### TypeSpec @example decorator Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/emitters/typespec-autorest/index.md Attach example files to an operation using the @example decorator. Multiple examples can be specified. ```typespec @example(pathOrUri, title) ``` -------------------------------- ### `@example` Decorator Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/emitters/typespec-autorest/reference/decorators.md The `@example` decorator attaches example files to an operation. It can be specified multiple times for an operation. ```APIDOC ## `@example` Decorator ### Description Attaches example files to an operation. Multiple examples can be specified. ### Target `Operation` ### Syntax ```typespec @Autorest.example(pathOrUri: valueof string, title: valueof string) ``` ### Parameters #### Path Parameters - **pathOrUri** (`valueof string`) - Required - path or Uri to the example file. - **title** (`valueof string`) - Required - name or description of the example file. ``` -------------------------------- ### Python SDK Example for Multiple Services Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/design-docs/multiple-services.md Instantiates and uses clients for two distinct services, ServiceA and ServiceB, demonstrating their individual usage. ```python # ServiceA client with custom name client_a = MyServiceAClient(endpoint="endpoint", credential=AzureKeyCredential("key")) client_a.operations.op_a() client_a.sub_namespace.sub_op_a() # ServiceB client with custom name client_b = MyServiceBClient(endpoint="endpoint", credential=AzureKeyCredential("key")) client_b.operations.op_b() client_b.sub_namespace.sub_op_b() ``` -------------------------------- ### TypeScript Client Initialization and Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/02package.mdx Demonstrates how to initialize a TypeScript client and use it to interact with a pet store service. ```typescript const client = new PetStoreClient(); const food: Food = { name: "food"; quantity: 3; } client.feed(food); ``` -------------------------------- ### Install @azure-tools/typespec-metadata Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-metadata/README.md Install the emitter using npm. ```bash npm install @azure-tools/typespec-metadata ``` -------------------------------- ### Install @azure-tools/typespec-autorest-canonical Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest-canonical/README.md Install the package using npm. ```bash npm install @azure-tools/typespec-autorest-canonical ``` -------------------------------- ### Go Client Initialization and Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Shows the generated Go code for StorageClient, including constructor, methods, and options. Demonstrates client initialization and method calls. ```go // generated storage_client.go type StorageClient struct {} func NewStorageClient(internal *azcore.Client, endpoint string, blobName string) *NewStorageClient{ return &NewStorageClient{ internal: internal, endpoint: endpoint, blobName: blobName } } func (client *StorageClient) Upload(ctx context.Context, options *StorageClientUploadOptions) (StorageClientUploadResponse, error) {} func (client *StorageClient) Download(ctx context.Context, options *StorageClientDownloadOptions) (StorageClientDownloadResponse, error) {} // generated options.go type StorageClientDownloadOptions {} type StorageClientUploadOptions {} // generated response.go type StorageClientDownloadResponse {} type StorageClientUploadResponse {} // Usage Sample client := NewStorageClient(nil,"","myBlobName") client.Upload(context.Background(), &StorageClientUploadOptions{}) client.Download(context.Background(), &StorageClientDownloadOptions{}) ``` -------------------------------- ### Install @azure-tools/typespec-autorest Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest/README.md Install the TypeSpec Autorest library using npm. ```bash npm install @azure-tools/typespec-autorest ``` -------------------------------- ### Go Client Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Shows how to create and use clients for operations in Go, including context and options. ```go // generated petstore_client.go type PetStoreClient struct {} func NewPetStoreClient() *PetStoreClient{ return &PetStoreClient{} } func (client *PetStoreClient)NewOpGrp1Client() *OpGrp1Client{ return &OpGrp1Client{} } func (client *PetStoreClient)NewOpGrp2Client() *OpGrp2Client{ return &OpGrp2Client{} } // generated petstoreopgrp1_client.go type OpGrp1Client struct {} func (client *PetStoreOpGrp1Client) Feed(ctx context.Context, options *PetStoreOpGrp1ClientFeedOptions) (PetStoreOpGrp1ClientFeedResponse, error) {} // generated petstoreopgrp2_client.go type OpGrp2Client struct {} func (client *PetStoreOpGrp2Client) Pet(ctx context.Context, options *PetStoreOpGrp2ClientPetOptions) (PetStoreOpGrp2ClientPetResponse, error) {} // generated options.go type PetStoreOpGrp1ClientFeedOptions struct {} type PetStoreOpGrp2ClientPetOptions struct {} // generated response.go type PetStoreOpGrp1ClientFeedResponse struct {} type PetStoreOpGrp2ClientPetResponse struct {} // Usage Sample petStoreClient := NewPetStoreClient() opGrp1Client := petStoreClient.NewOpGrp1Client() opGrp1Client.Feed(context.Background(), &PetStoreOpGrp1ClientFeedOptions{}) opGrp2Client := petStoreClient.NewOpGrp2Client() opGrp2Client.Pet(context.Background(),&PetStoreOpGrp2ClientPetOptions{}) ``` -------------------------------- ### Install @azure-tools/typespec-azure-rulesets Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-azure-rulesets/README.md Install the Azure rulesets package using npm. ```bash npm install @azure-tools/typespec-azure-rulesets ``` -------------------------------- ### Generate Examples with oav Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/migrate-swagger/faq/x-ms-examples.mdx Use the oav tool to generate basic examples from your OpenAPI JSON file. You will need to manually modify these generated examples to include meaningful values. ```bash oav generate-examples openapi.json ``` -------------------------------- ### ArmResourceCreatedSyncResponse Example Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md Example of using ArmResourceCreatedSyncResponse for a synchronous create or update operation. ```typespec op createOrUpdate is ArmResourceCreateOrReplaceSync< Employee, Response = ArmResponse | ArmResourceCreatedSyncResponse >; ``` -------------------------------- ### Initialize Client and Sub-Client Independently (Same Parameters) Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/design-docs/client.md Demonstrates initializing a client and a sub-client, where the sub-client can also be initialized independently with the same parameters as the parent. ```Python client = TestClient(endpoint="endpoint", credential=AzureKeyCredential("key")) client.do_something() sub_client = client.sub_client() sub_client.do_something() sub_client = TestSubClient(endpoint="endpoint", credential=AzureKeyCredential("key")) sub_client.do_something() ``` -------------------------------- ### TypeSpec Decorator: @example Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest/README.md Attaches example files to an operation. Can be specified on Operations. ```typespec @Autorest.example(pathOrUri: valueof string, title: valueof string) ``` -------------------------------- ### Python SDK Usage for ServiceA and ServiceB Clients Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/design-docs/multiple-services.md Demonstrates how to instantiate and use clients for ServiceA and ServiceB in Python, including calling their respective operations and sub-namespace methods. ```python # ServiceA client (auto-generated name) client_a = ServiceAClient(endpoint="endpoint", credential=AzureKeyCredential("key")) client_a.operations.op_a() client_a.sub_namespace.sub_op_a() # ServiceB client (auto-generated name) client_b = ServiceBClient(endpoint="endpoint", credential=AzureKeyCredential("key")) client_b.operations.op_b() client_b.sub_namespace.sub_op_b() ``` -------------------------------- ### Install TypeSpec Azure Resource Manager Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-azure-resource-manager/README.md Install the library using npm. ```bash npm install @azure-tools/typespec-azure-resource-manager ``` -------------------------------- ### TrackedResource GET Operation Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/ARM/resource-operations.md Represents the GET operation for a TrackedResource, which is recommended and required. ```typescript get is ArmResourceRead; ``` -------------------------------- ### Python SDK Example for Mixed Clients Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/design-docs/multiple-services.md Demonstrates the instantiation and usage of both a combined multi-service client (CombinedABClient) and a single-service client (ServiceCClient). ```python # Combined client for ServiceA and ServiceB combined_client = CombinedABClient(endpoint="endpoint", credential=AzureKeyCredential("key")) combined_client.operations.op_a() # From ServiceA combined_client.operations.op_b() # From ServiceB # Separate client for ServiceC service_c_client = ServiceCClient(endpoint="endpoint", credential=AzureKeyCredential("key")) service_c_client.operations.op_c() ``` -------------------------------- ### Update API Version in Example JSON Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Versioning/02-preview-after-preview.md Modify the 'api-version' field within example JSON files to match the new preview API version. This ensures examples are compatible with the updated spec. ```diff { "title": "Create a Widget", "operationId": "Widgets_Create", "parameters": { - "api-version": "2025-12-01-preview", + "api-version": "2026-01-01-preview", } } ``` -------------------------------- ### ArmResourceExistsResponse Example Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md Example of a HEAD operation to check for resource existence, returning ArmResourceExistsResponse. ```typespec @head op head(...ResourceInstanceParameters): ArmResourceExistsResponse; ``` -------------------------------- ### Example emitter-package.json Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate with tsp-client/repo_setup.md This file configures the emitters and their dependencies for client library generation. Ensure the 'main' field is present as required by tsp compile. ```json { "main": "dist/src/index.js", "dependencies": { "@azure-tools/typespec-python": "0.21.0" } } ``` -------------------------------- ### Development and Build Commands Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-azure-playground-website/README.md Commands to start the website in development mode, build for production, or preview the production build. ```bash npm start ``` ```bash npm run preview ``` ```bash npm run build ``` -------------------------------- ### Azure Example Basic Request and Response Source: https://github.com/azure/typespec-azure/blob/main/packages/azure-http-specs/spec-summary.md Demonstrates a basic Azure POST operation. Requires setting the 'examples-dir' option during code generation. Specifies expected query parameters, header parameters, input body, and response body. ```json { "stringProperty": "text", "modelProperty": { "int32Property": 1, "float32Property": 1.5, "enumProperty": "EnumValue1" }, "arrayProperty": ["item"], "recordProperty": { "record": "value" } } ``` ```json { "stringProperty": "text" } ``` -------------------------------- ### Install Core Azure TypeSpec Packages Source: https://context7.com/azure/typespec-azure/llms.txt Install the necessary TypeSpec packages for Azure development, including core libraries, resource manager support, and client generation tools. Use npm for installation. ```bash # Install packages npm install @typespec/rest @typespec/versioning @azure-tools/typespec-azure-core @azure-tools/typespec-autorest # For ARM (Azure Resource Manager) services, also install: npm install @azure-tools/typespec-azure-resource-manager # For client SDK customization: npm install @azure-tools/typespec-client-generator-core # Compile the TypeSpec project tsp compile . # Compile and emit Autorest/Swagger directly from CLI tsp compile . --emit=@azure-tools/typespec-autorest ``` -------------------------------- ### Python Client Example for Multiple Services Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-client-generator-core/design-docs/multiple-services.md Demonstrates how a Python client can interact with different services (Disk and Gallery) from a single client instance, using their respective API versions. ```python client = ComputeManagementClient(credential=DefaultAzureCredential(), subscription_id="{subscription-id}") client.disks.list_by_resource_group(resource_group_name="myResourceGroup") # this operation will use API version defined in Disk service client.galleries.list(location="eastus") # this operation will use API version defined in Gallery service ``` -------------------------------- ### Go Client Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Example of how to use generated Go client libraries for Food and PetAction services. ```go // generated food_client.go type FoodClient struct {} func NewFoodClient() *FoodClient{ return &FoodClient{} } func (client *FoodClient) Feed(ctx context.Context, options *FoodClientFeedOptions) (FoodClientFeedResponse, error) {} // generated pet_action_client.go package newpetstore type PetActionClient struct {} func NewPetActionClient() *PetActionClient{ return &PetActionClient{} } func (client *PetActionClient) Pet(ctx context.Context, options *PetActionClientPetOptions) (PetActionClientPetResponse, error) {} // generated options.go type FoodClientFeedOptions struct {} type PetActionClientPetOptions struct {} // generated response.go type FoodClientFeedResponse struct {} type PetActionClientPetResponse struct {} // Usage Sample foodClient := NewFoodClient() foodClient.Feed(context.Background(), &FoodClientFeedOptions{}) petClient := NewPetActionClient() petClient.Pet(context.Background(), &PetActionClientPetOptions{}) ``` -------------------------------- ### ArmResourceCreatedResponse Example Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md Example of using ArmResourceCreatedResponse for a create or update operation that returns LRO headers. ```typespec op createOrUpdate is ArmResourceCreateOrReplaceAsync< Employee, Response = | ArmResponse | ArmResourceCreatedResponse< Employee, LroHeaders = ArmLroLocationHeader & Azure.Core.Foundations.RetryAfterHeader > >; ``` -------------------------------- ### Example: Multiple services output file names Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-autorest-canonical/README.md Configure the output file names for multiple services. ```yaml Service1.canonical.openapi.json Service2.canonical.openapi.json ``` -------------------------------- ### Install TypeSpec Azure Core Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-azure-core/README.md Install the TypeSpec Azure Core library using npm. ```bash npm install @azure-tools/typespec-azure-core ``` -------------------------------- ### Example of TrackedResourceWithOptionalLocation Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md An example demonstrating how to alias TrackedResourceWithOptionalLocation to create an Employee resource, incorporating ResourceNameParameter. ```typespec model Employee is TrackedResourceWithOptionalLocation { ...ResourceNameParameter; } ``` -------------------------------- ### Go Client Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Instantiate and use the PetStore client, including its cats and dogs sub-clients, with context and options. ```go // generated petstore_client.go type PetStoreClient struct {} func (client *PetStoreClient) NewPetStoreCatsClient() *PetStoreCatsClient { return &PetStoreCatsClient{} } func (client *PetStoreClient) NewPetStoreDogsClient() *PetStoreDogsClient { return &PetStoreDogsClient{} } // generated petstoredogs_client.go type PetStoreDogsClient struct {} func (client *PetStoreDogsClient) Feed(ctx context.Context, options *PetStoreDogsClientFeedOptions) (PetStoreDogsClientFeedResponse, error) {} func (client *PetStoreDogsClient) Pet(ctx context.Context, options *PetStoreDogsClientPetOptions) (PetStoreDogsClientPetResponse, error) {} // generated petstorecats_client.go type PetStoreCatsClient struct {} func (client *PetStoreCatsClient) Feed(ctx context.Context, options *PetStoreCatsClientFeedOptions) (PetStoreCatsClientFeedResponse, error) {} func (client *PetStoreCatsClient) Pet(ctx context.Context, options *PetStoreCatsClientPetOptions) (PetStoreCatsClientPetResponse, error) {} // generated options.go type PetStoreDogsClientFeedOptions struct {} type PetStoreDogsClientPetOptions struct {} type PetStoreCatsClientFeedOptions struct {} type PetStoreCatsClientPetOptions struct {} // generated response.go type PetStoreDogsClientFeedResponse {} type PetStoreDogsClientPetResponse {} type PetStoreCatsClientFeedResponse {} type PetStoreCatsClientPetResponse {} // Usage Sample petStoreClient := NewPetStoreClient() petStoreCatsClient := petStoreClient.NewPetStoreCatsClient() petStoreCatsClient.Feed(context.Background(), &PetStoreCatsClientFeedOptions{}) petStoreCatsClient.Pet(context.Background(), &PetStoreCatsClientPetOptions{}) petStoreDogsClient := petStoreClient.NewPetStoreDogsClient() petStoreDogsClient.Feed(context.Background(), &PetStoreDogsClientFeedOptions{}) petStoreDogsClient.Pet(context.Background(), &PetStoreDogsClientPetOptions{}) ``` -------------------------------- ### Python Client Library Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Demonstrates initializing the PetStore client and calling various operations like info, history, feed, and pet. Ensure the PetStore client is correctly imported. ```python from pet_store import PetStoreClient client = PetStoreClient() client.info() client.billings.history() client.pets.info() client.pets.actions.feed() client.pets.actions.pet() client.actions.open() client.actions.close() ``` -------------------------------- ### Example Employee Resource Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md Example of an Employee resource extending TrackedResource with specific properties and name parameters. ```typespec @parentResource(TenantLocationResource) model Employee is TrackedResource { ...ResourceNameParameter; } ``` -------------------------------- ### Install @azure-tools/typespec-python Source: https://github.com/azure/typespec-azure/blob/main/packages/typespec-python/README.md Install the TypeSpec emitter for Python SDKs using npm. This is a prerequisite for using the emitter. ```bash npm install @azure-tools/typespec-python ``` -------------------------------- ### Go Client Library Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Provides examples for using the generated Go client libraries, including creating clients and calling Feed and Pet methods with context and options. ```go // generated food_client.go type FoodClient struct {} func NewFoodClient() *FoodClient{ return &FoodClient{} } func (client *FoodClient) Feed(ctx context.Context, options *FoodClientFeedOptions) (FoodClientFeedResponse, error) {} // generated pet_action_client.go package petstorerenamed type PetActionClient struct {} func NewPetActionClient() *PetActionClient{ return &PetActionClient{} } func (client *PetActionClient) Pet(ctx context.Context, options *PetActionClientPetOptions) (PetActionClientPetResponse, error) {} // generated options.go type FoodClientFeedOptions struct {} type PetActionClientPetOptions struct {} // generated response.go type FoodClientFeedResponse struct {} type PetActionClientPetResponse struct {} // Usage Sample foodClient := NewFoodClient() foodClient.Feed(context.Background(), &FoodClientFeedOptions{}) petClient := NewPetActionClient() petClient.Pet(context.Background(), &PetActionClientPetOptions{}) ``` -------------------------------- ### Python Client Initialization with Custom Parameters Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Example of a generated Python client constructor that includes a custom initialization parameter. ```python # generated _client.py class StorageClient(_StorageClientOperationsMixin): def __init__(self, endpoint: str, blob_name: str, **kwargs: Any) -> None: ... # generated _operations/_operations.py class _StorageClientOperationsMixin: @distributed_trace def upload(self, **kwargs: Any) -> None: @distributed_trace def download(self, **kwargs: Any) -> None: #usage sample from storage import StorageClient client = StorageClient(endpoint="", blob_name="myBlobName", ...) client.upload() client.download() ``` -------------------------------- ### Resource Get Operation Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/ARM/resource-operations.md Retrieves a single resource. This operation is typically mapped to an HTTP GET request. ```APIDOC ## GET /resource ### Description Retrieves a single resource. ### Method GET ### Endpoint /resource ### Parameters None explicitly defined in this snippet, but typically includes resource identifier in the path. ### Request Example None provided. ### Response #### Success Response (200) - **resource** (object) - The retrieved resource object. #### Response Example None provided. ``` -------------------------------- ### Preview Production Build Locally Source: https://github.com/azure/typespec-azure/blob/main/website/README.md Run this command to preview your production build locally before deploying. This ensures the site functions as expected in a production-like environment. ```bash pnpm preview ``` -------------------------------- ### Example ARM Delete Operation with LRO Response Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md An example of a delete operation that can return either an ArmDeleteAcceptedLroResponse or an ArmDeletedNoContentResponse. ```typespec op delete is ArmResourceDeleteWithoutOkAsync< Employee, Response = ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse >; ``` -------------------------------- ### Update API Version in Examples Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Versioning/03-stable-after-preview.md Search and replace the `api-version` in all example files to reflect the new stable version. ```json { "title": "Create a Widget", "operationId": "Widgets_Create", "parameters": { - "api-version": "2025-12-01-preview", + "api-version": "2026-01-01", } } ``` -------------------------------- ### Combined and Separate Client Usage (Go) Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Provides an example of using combined and separate clients in Go, including context and options for operations. Assumes generated client functions. ```go // Combined client for ServiceA and ServiceB combinedClient := NewCombinedABClient("") opsClient := combinedClient.NewOperationsClient() opsClient.OpA(context.Background(), &OperationsClientOpAOptions{}) // From ServiceA opsClient.OpB(context.Background(), &OperationsClientOpBOptions{}) // From ServiceB // Separate client for ServiceC serviceCClient := NewServiceCClient("") serviceCOps := serviceCClient.NewOperationsClient() serviceCOps.OpC(context.Background(), &OperationsClientOpCOptions{}) ``` -------------------------------- ### Java Client Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Demonstrates building and using clients for operations in Java. Includes client builder, operation group clients, and usage examples. ```java // Client builder class package petstorerenamed; @ServiceClientBuilder( serviceClients = { OpGrp1Client.class, OpGrp2Client.class, OpGrp1AsyncClient.class, OpGrp2AsyncClient.class }) public final class PetStoreClientBuilder implements HttpTrait, ConfigurationTrait, EndpointTrait { public OpGrp1Client buildOpGrp1Client(); public OpGrp2Client buildOpGrp2Client(); } // Client class @ServiceClient(builder = PetStoreClientBuilder.class) public final class OpGrp1Client { public void feed(); } @ServiceClient(builder = PetStoreClientBuilder.class) public final class OpGrp2Client { public void pet(); } // Usage package petstorerenamed; PetStoreClientBuilder builder = new PetStoreClientBuilder(); OpGrp1Client opGrp1Client = builder.buildOpGrp1Client(); opGrp1Client.feed(); OpGrp2Client opGrp2Client = builder.buildOpGrp2Client(); opGrp2Client.pet(); ``` -------------------------------- ### CombineClient Initialization and Service Access in Go Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Initializes a CombineClient and demonstrates accessing operations from ServiceA via ComputeClient and ServiceB via DiskClient in Go. ```go combineClient := NewCombineClient("") // Access ServiceA operations via ComputeClient computeClient := combineClient.NewComputeClient() computeOps := computeClient.NewOperationsClient() computeOps.OpA(context.Background(), &OperationsClientOpAOptions{}) computeSub := computeClient.NewSubNamespaceClient() computeSub.SubOpA(context.Background(), &SubNamespaceClientSubOpAOptions{}) // Access ServiceB operations via DiskClient diskClient := combineClient.NewDiskClient() diskOps := diskClient.NewOperationsClient() diskOps.OpB(context.Background(), &OperationsClientOpBOptions{}) diskSub := diskClient.NewSubNamespaceClient() diskSub.SubOpB(context.Background(), &SubNamespaceClientSubOpBOptions{}) ``` -------------------------------- ### Java Client Usage Source: https://github.com/azure/typespec-azure/blob/main/website/src/content/docs/docs/howtos/Generate client libraries/03client.mdx Example of how to use generated Java client libraries for Food and PetAction services, including client builders. ```java package newstore.food; // Client builder class @ServiceClientBuilder(serviceClients = { FoodClient.class, FoodAsyncClient.class }) public final class FoodClientBuilder implements HttpTrait, ConfigurationTrait, EndpointTrait { public FoodClientBuilder(); public FoodClient buildClient(); } // Client class @ServiceClient(builder = FoodClientBuilder.class) public final class FoodClient { public void feed(); } package newstore.petaction; // Client builder class @ServiceClientBuilder(serviceClients = { PetActionClient.class, PetActionAsyncClient.class }) public final class PetActionClientBuilder implements HttpTrait, ConfigurationTrait, EndpointTrait { public PetActionClientBuilder(); public PetActionClient buildClient(); } // Client class @ServiceClient(builder = PetActionClientBuilder.class) public final class PetActionClient { public void pet(); } // Usage import newpetstore.food.FoodClient; import newpetstore.food.FoodClientBuilder; import newpetstore.petaction.PetActionClient; import newpetstore.petaction.PetActionClientBuilder; FoodClient foodClient = new FoodClientBuilder().buildClient(); foodClient.feed(); PetActionClient petActionClient = new PetActionClientBuilder().buildClient(); petActionClient.pet(); ```