Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update the document for client generation #1774

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/howtos/Client Generation/01setup.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: Setup for SDK customization
title: Setup for SDK Customization
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

This page explains how to setup customization of a generator if necessary.
This page provides instructions on setting up customization for TypeSpec to include client-specific customizations in the generated code.

Your `package.json` needs to contains a link to the customization library, `typespec-client-generator-core`:
Ensure that your `package.json` includes a link to the customization library, `typespec-client-generator-core`:

```json
{
Expand All @@ -23,7 +23,7 @@ Your `package.json` needs to contains a link to the customization library, `type
}
```

Customization should always be done in a file called `client.tsp` along with the `main.tsp`.
Customization should be implemented in a file named `client.tsp`, which should be used alongside with the `main.tsp`.

```typespec
// client.tsp
Expand All @@ -32,10 +32,10 @@ import "@azure-tools/typespec-client-generator-core";

using Azure.ClientGenerator.Core;

// Your customizations here
// Add your customizations here
```

Once you have a customization file, you should compile with your client.tsp to get output that includes the customizations:
After you've created your customization file, use the command `tsp compile client.tsp` to generate output that includes your customizations:

```shell
tsp compile client.tsp
Expand Down
35 changes: 28 additions & 7 deletions docs/howtos/Client Generation/02client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,37 @@ title: Client hierarchy
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

This page documents the default client hierarchy behavior as well as how to customize clients. For an overview of the setup, please visit the previous page.
This page documents the default client hierarchy behavior as well as how to customize clients. To get a summary of the setup, please check out the previous page.

JS RLC is not in the business of customization. it will ignore client.tsp and the follow scenarios will not have impact on the JS RLC user experiences. In this context, TypeScript part means JS Modular Emitter.
The JS RLC doesn't support client hierarchy customization and will ignore client.tsp. Therefore, the following scenarios won't affect the JS RLC user experience. In this context, the TypeScript part refers to the JS Modular Emitter.

## Default behavior

By default, each namespace with `@service` decorator will be generated as a root client. The name for that client will be the namespace name concatenating `Client` as suffix.
Each namespace with `@service` decorator will automatically be generated as a root client by default. The client's name will be the namespace name with `Client` added as suffix.

Other nested namespacess and interfaces of each root client will be generated as operation groups with hierarchy.
Nested namespaces and interfaces within each root client will be generated as operation groups with hierarchy.

Different language's code generator will have different way to organize clients and operation groups. Please refer the following examples.
Code generators for different languages will organize clients and operation groups in various ways. Please refer the following examples:

### Single client

<Tabs>
<TabItem value="typespec" label="TypeSpec" default>

```typespec
using TypeSpec.Versioning;
using TypeSpec.Http;

@versioned(Versions)
@service({
title: "Pet Store",
version: "v1",
})
namespace PetStore;

enum Versions {
v1,
}

@route("/feed")
op feed(): void;

Expand All @@ -52,9 +59,23 @@ client.pet()
<TabItem value="csharp" label="CSharp" >

```csharp
namespace PetStore
{
public partial class PetStoreClient
{
public PetStoreClient(Uri endpoint, PetStoreClientOptions options){}

public virtual async Task<Response> FeedAsync(RequestContext context = null) {}
public virtual Response Feed(RequestContext context = null) {}
public virtual async Task<Response> PetAsync(RequestContext context = null) {}
public virtual Response Pet(RequestContext context = null) {}
}
}

// Create the client and invoke the operations
using PetStore;

PetStoreClient client = new PetStoreClient();
PetStoreClient client = new PetStoreClient(url, options);
client.Feed();
client.Pet();
```
Expand Down
Loading