diff --git a/website/src/content/docs/docs/howtos/Generate client libraries/02client.mdx b/website/src/content/docs/docs/howtos/Generate client libraries/02client.mdx index e1a0d0bf0d..fc6a92e815 100644 --- a/website/src/content/docs/docs/howtos/Generate client libraries/02client.mdx +++ b/website/src/content/docs/docs/howtos/Generate client libraries/02client.mdx @@ -1,5 +1,5 @@ --- -title: Client hierarchy +title: Clients --- import { ClientTabs, ClientTabItem } from "@components/client-tabs"; @@ -555,3 +555,77 @@ petActionClient.pet(); ``` + +### Adding Client Initialization Parameters + +By default, we only generate our clients with initialization parameters for `endpoint`, `credential`, and `apiVersion`, whenever any of these are applicable. There are cases where spec authors would like their clients to have additional input parameters. This is where the `@clientInitialization` decorator comes in. + +With `@clientInitialization`, you can pass in additional parameters you would like your client to have, by passing in an input model. All properties of the input model will be appended to the current default list of client initialization parameters. Additionally, these client parameters will no longer appear on service methods that previously had them as part of the method signature. The generated code will automatically pass in the inputted value from the client init to the service. + + + +```typespec title="main.tsp" +@service +namespace Storage; + +op upload(@path blobName: string): void; +op download(@path blobName: string): void; +``` + +```typespec title="client.tsp" +import "./main.tsp"; +import "@azure-tools/typespec-client-generator-core"; + +using Azure.ClientGenerator.Core; + +namespace Customizations; + +model StorageClientOptions { + blobName: string; +} + +@@clientInitialization(Storage, StorageClientOptions); +``` + +```python +from storage import StorageClient + +client = StorageClient(endpoint="", blob_name="myBlobName", ...) + +client.upload() +client.download() +``` + +```csharp +// TODO: how do you pass in the options model +using Storage; + +StorageClient client = new StorageClient(); + +client.Upload(); +client.Download(); +``` + +```typescript +// TODO: how do you pass in the options model +import { StorageClient } from "@azure/package-name"; + +const client = new StorageClient(); + +client.upload(); +client.download(); +``` + +```java +package storage; + +StorageClient client = new StorageClient() + .endpoint("") + .blobName("myBlobName") + .buildClient(); + +client.upload() +client.download() +``` + +