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

Add the introduction of emitters for sdk clients. #5663

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
122 changes: 122 additions & 0 deletions website/src/content/docs/docs/emitters/sdk-clients/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: introduction of SDK client emitters
---

## How to Use Client Emitters to Generate SDK from TypeSpec

### Introduction

This guide will walk you through the process of using different client emitters (JavaScript, Python, Java, .NET) to generate SDKs from TypeSpec. Please note that all client emitters are currently in **preview** and are subject to changes in future versions.

By following this guide, you will learn:

1. How to set up and configure client emitters.
2. Update the client emitter configurations in `package.json` and `tspconfig.yaml`.
3. How to run the SDK generation for each specific programming language.

## Location of All Client Emitters and Common Configurations

The client emitters and their common configurations are located in the `package.json` file within your project.

| **Emitter Name** | **Language** | **Version** | **Common Configuration** |
| ---------------------------- | ------------ | ------------------------ | ------------------------ |
| @azure-tools/typespec-ts | JavaScript | `0.38.1` | `emitter-output-dir` |
| @typespec/http-client-python | Python | `0.6.6` | `emitter-output-dir` |
| @typespec/http-client-java | Java | `0.1.9` | `emitter-output-dir` |
| @typespec/http-client-csharp | .NET | `0.1.9-alpha.20250113.2` | `emitter-output-dir` |

### Common Configuration Options

- `emitter-output-dir`: Defines where the generated SDK files will be stored.

Below is an example of the `package.json` snippet where client emitters are defined:

```json
"dependencies": {
"@typespec/http-client-csharp": "^0.1.9-alpha.20250113.2",
"@typespec/http-server-javascript": "^0.58.0-alpha.6",
"@typespec/http-client-java": "^0.1.9",
"@typespec/http-client-python": "^0.6.6",
"@azure-tools/typespec-ts": "^0.37.0",
}
```

#### Note: Check for the Latest Version

To ensure you are using the latest version of the packages, visit npmjs.com and search for the relevant packages.

## Language-Specific Settings

### JavaScript Client Emitter

lirenhe marked this conversation as resolved.
Show resolved Hide resolved
Generally no additional setting is required for JavaScript. However it's recommended to specify `packageDetails` which would provide package metadata in `package.json` and `README.md` files.

#### packageDetails

Provide the metadata for `package.json`, `README.md` information.

| Property | Description |
| ----------- | ---------------------------------------------------------------------- |
| name | Package name used in `package.json` |
| description | Package description used in `package.json` file |
| version | Detailed version for your package, the default value is `1.0.0-beta.1` |

Example configuration:

```yaml
packageDetails:
name: "${your_package_name}"
version: 1.0.0
```

### Python Client Emitter

msyyc marked this conversation as resolved.
Show resolved Hide resolved
### Java Client Emitter

No additional setting needed for Java.

### .NET Client Emitter

## Running Language-Specific Emitters in CLI

1. Ensure that your package.json file is correctly configured to include the necessary dependencies for running the emitters

1. Update the tspconfig.yaml file for properly configured for the language-specific emitter.

```yaml
emit:
- "@typespec/http-client-csharp"
- "@typespec/http-client-java"
- "@typespec/http-client-python"
- "@azure-tools/typespec-ts"
options:
"@typespec/http-client-csharp":
emitter-output-dir: "{project-root}/../clients/dotnet"
"@typespec/http-client-java":
emitter-output-dir: "{project-root}/../clients/java"
"@typespec/http-client-python":
emitter-output-dir: "{project-root}/../clients/python"
"@azure-tools/typespec-ts":
emitter-output-dir: "{project-root}/../clients/javascript"
packageDetails:
name: "${your_package_name}"
version: 1.0.0
```

1. Once the package.json and tspconfig.yaml files are updated, you need to install all required dependencies.

Run the following command:

```bash
tsp install
```

2. Run the emitter to compile your TypeScript code into the desired language. Use the following command to trigger the emitter and compile your project:

```bash
tsp compile .
```

## Disclaimer

> **All client emitters are in preview**. These emitters are actively being developed and may experience changes or updates that could affect their functionality. Please follow the official documentation for the latest updates.
Loading