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 11 commits into
base: main
Choose a base branch
from
134 changes: 134 additions & 0 deletions website/src/content/docs/docs/emitters/sdk-clients/introduction.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page is not showing on the website. Make sure it is included in the sidebar

Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
---
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuration is in the tspconfig.yaml no?


| **Emitter Name** | **Language** | **Version** | **Common Configuration** |
| ---------------------------- | ------------ | ------------------------ | ------------------------ |
| @azure-tools/typespec-ts | JavaScript | `0.38.1` | `emitter-output-dir` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think you should include the version here, this will immediately be out of date. If it is important to have it you can use npm badges to have it on the fly

![](https://img.shields.io/npm/v/@typespec/compiler) 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure also what common configuration means here

| @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-client-java": "^0.1.9",
"@typespec/http-client-python": "^0.6.6",
"@azure-tools/typespec-ts": "^0.38.1",
}
```

#### Note: Check for the Latest Version

To ensure you are using the latest version of the packages, visit [npmjs](https://www.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
No additional setting needed for Python.

### Java Client Emitter

#### Required Dependencies

Java (Java Development Kit) and Maven (Apache Maven) is required to be installed, before running Java client emitter.

The required version and the URL for downloading is specified below:

- [Java](https://docs.microsoft.com/java/openjdk/download) 17 or above. (Verify by running `java --version`)
- [Maven](https://maven.apache.org/download.cgi). (Verify by running `mvn --version`)

#### Configuration Options for Java

No additional setting needed for Java.

### .NET Client Emitter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal of this section to list the available options or to list additional required options? If no languages have any other required options, is there any reason to retain each language option section? If the goal is to list all the additional options, then there are several other options for .NET. https://github.com/microsoft/typespec/blob/main/packages/http-client-csharp/emitter/src/options.ts#L10-L26

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah +1, not sure what the point is of this section, we shouldn't have any required option to start.


## 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use starlight steps to hav ea nicely presented stepped tutorial https://starlight.astro.build/components/steps/


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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are the path going .., this make some assumption that they want to add it outside of their project which I would think is not what someone would epxect when getting started(start poluting some other folder)

"@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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include instructions for installing the dependencies?


Run the following command:

```bash
tsp install
```

1. 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 .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we clarify that this will only work if main.tsp is defined in the current directory? It might be better to specify the path to the tsp that you wish to 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we link to the official documentation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good that we include it right there on the website as well(in the same way we have docs for the other emitters)

Copy link
Member

@timotheeguerin timotheeguerin Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use asides for notes/warning, etc. https://starlight.astro.build/components/asides/

:::note
...
:::

Loading