Skip to content

Commit 24195cc

Browse files
committed
Co-authored-by: catalinaperalta <[email protected]>
Update package.json
1 parent b30bd53 commit 24195cc

17 files changed

Lines changed: 3664 additions & 429 deletions

tools/tsp-client/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules
33
dist
44
types
55
temp
6+
tsp-output/
7+
output/

tools/tsp-client/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Added `generate-lock-file` command, see [README](https://github.com/Azure/azure-sdk-tools/blob/main/tools/tsp-client/README.md) for more information.
1010
- Removed the `--generate-lock-file` flag and replaced it with the command above.
1111
- Migrated tsp-client from `node:util` to `yargs` for commandline infrastructure.
12+
- Added `compare` command to compare a hand-authored Swagger to a TypeSpec-generated Swagger to understand the relevant differences between them.
1213

1314
## 2024-08-05 - 0.10.0
1415

tools/tsp-client/README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,72 @@
33
A simple command line tool to facilitate generating client libraries from TypeSpec.
44

55
## Installation
6+
67
```
78
npm install @azure-tools/typespec-client-generator-cli
89
```
910

1011
## Prerequisites
12+
1113
Please note that these prerequisites apply on the repository where the client library is going to be generated. Repo owners should make sure to follow these prerequisites. Users working with a repository that already accepts this tool can continue to see the [Usage](#usage) section.
1214

1315
- Add an emitter-package.json to the repo following this [configuration](#emitter-packagejson).
1416
- Add the [TempTypeSpecFiles](#TempTypeSpecFiles) directory to the .gitignore file for your repository.
1517

1618
## Usage
19+
1720
```
1821
tsp-client <command> [options]
1922
```
2023

2124
## Commands
25+
2226
Use one of the supported commands to get started generating clients from a TypeSpec project.
2327
This tool will default to using your current working directory to generate clients in and will
2428
use it to look for relevant configuration files. To specify a different output directory, use
2529
the `-o` or `--output-dir` option.
2630

2731
### init
32+
2833
Initialize the client library directory using a tspconfig.yaml. When running this command pass in a path to a local or remote tspconfig.yaml with the `-c` or `--tsp-config` flag.
2934

3035
The `init` command generates a directory structure following the standard pattern used across Azure SDK language repositories, creates a [tsp-location.yaml](#tsp-locationyaml) file to control generation, and performs an initial generation of the client library. If you want to skip client library generation, then pass the `--skip-sync-and-generate` flag.
3136

3237
> IMPORTANT: This command should be run from the root of the repository.
3338
3439
### update
40+
3541
Sync and generate client libraries from a TypeSpec project. The `update` command will look for a [tsp-location.yaml](#tsp-locationyaml) file in your current directory to sync a TypeSpec project and generate a client library.
3642

3743
### sync
44+
3845
Sync a TypeSpec project with the parameters specified in tsp-location.yaml.
3946

4047
By default the `sync` command will look for a tsp-location.yaml to get the project details and sync them to a temporary directory called `TempTypeSpecFiles`. Alternately, you can pass in the `--local-spec-repo` flag with the path to your local TypeSpec project to pull those files into your temporary directory.
4148

4249
### generate
50+
4351
Generate a client library from a TypeSpec project. The `generate` command should be run after the `sync` command. `generate` relies on the existence of the `TempTypeSpecFiles` directory created by the `sync` command and on an `emitter-package.json` file checked into your repository at the following path: `<repo root>/eng/emitter-package.json`. The `emitter-package.json` file is used to install project dependencies and get the appropriate emitter package.
4452

4553
### convert
54+
4655
Convert an existing swagger specification to a TypeSpec project. This command should only be run once to get started working on a TypeSpec project. TypeSpec projects will need to be optimized manually and fully reviewed after conversion. When using this command a path or url to a swagger README file is required through the `--swagger-readme` flag.
4756

57+
### compare
58+
59+
Compares two Swagger definitions to identify the relevant differences between them. This command is useful when comparing an existing Swagger definition with a TypeSpec generated one. The `compare` command requires two parameters: `--lhs` which will typically be the original hand-authored Swagger and `--rhs` which will usually be the folder containing your TypeSpec. The command will generate the Swagger and compare the two definitions. The command will ignore differences in the Swagger that don't
60+
correspond to differences in the service, allowing you to focus only on differences that are relevant.
61+
4862
### sort-swagger
63+
4964
Sort an existing swagger specification to be the same content order with TypeSpec generated swagger. This will allow you to easily compare and identify differences between the existing swagger and TypeSpec generated one. You should run this command on existing swagger files and check them in prior to creating converted TypeSpec PRs.
5065

5166
### generate-lock-file
5267

5368
Generate an emitter-package-lock.json under the eng/ directory based on existing `<repo-root>/eng/emitter-package.json`.
5469

5570
## Options
71+
5672
```
5773
--arm Convert ARM swagger specification to TypeSpec [boolean]
5874
-c, --tsp-config The tspconfig.yaml file to use [string]
@@ -65,9 +81,9 @@ Generate an emitter-package-lock.json under the eng/ directory based on existing
6581
--save-inputs Don't clean up the temp directory after generation [boolean]
6682
--skip-sync-and-generate Skip sync and generate during project init [boolean]
6783
--swagger-readme Path or url to swagger readme file [string]
68-
-o, --output-dir Specify an alternate output directory for the
84+
-o, --output-dir Specify an alternate output directory for the
6985
generated files. Default is your current directory [string]
70-
--repo Repository where the project is defined for init
86+
--repo Repository where the project is defined for init
7187
or update [string]
7288
-v, --version Show version number [boolean]
7389
```
@@ -91,22 +107,23 @@ tsp-client update
91107
## Important concepts
92108

93109
### Per project setup
110+
94111
Each project will need to have a configuration file called tsp-location.yaml that will tell the tool where to find the TypeSpec project.
95112

96113
#### tsp-location.yaml
97114

98-
This file is created through the `tsp-client init` command or you can manually create it under the project directory to run other commands supported by this tool.
115+
This file is created through the `tsp-client init` command or you can manually create it under the project directory to run other commands supported by this tool.
99116

100117
> NOTE: This file should live under the project directory for each service.
101118
102119
The file has the following properties:
103120

104-
| Property | Description | IsRequired |
105-
| --- | --- | --- |
106-
| <a id="directory-anchor"></a> directory | The top level directory where the main.tsp for the service lives. This should be relative to the spec repo root such as `specification/cognitiveservices/OpenAI.Inference` | true |
107-
| <a id="additionalDirectories-anchor"></a> additionalDirectories | Sometimes a typespec file will use a relative import that might not be under the main directory. In this case a single `directory` will not be enough to pull down all necessary files. To support this you can specify additional directories as a list to sync so that all needed files are synced. | false: default = null |
108-
| <a id="commit-anchor"></a> commit | The commit sha for the version of the typespec files you want to generate off of. This allows us to have idempotence on generation until we opt into pointing at a later version. | true |
109-
| <a id="repo-anchor"></a> repo | The repo this spec lives in. This should be either `Azure/azure-rest-api-specs` or `Azure/azure-rest-api-specs-pr`. Note that pr will work locally but not in CI until we add another change to handle token based auth. | true |
121+
| Property | Description | IsRequired |
122+
| --------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
123+
| <a id="directory-anchor"></a> directory | The top level directory where the main.tsp for the service lives. This should be relative to the spec repo root such as `specification/cognitiveservices/OpenAI.Inference` | true |
124+
| <a id="additionalDirectories-anchor"></a> additionalDirectories | Sometimes a typespec file will use a relative import that might not be under the main directory. In this case a single `directory` will not be enough to pull down all necessary files. To support this you can specify additional directories as a list to sync so that all needed files are synced. | false: default = null |
125+
| <a id="commit-anchor"></a> commit | The commit sha for the version of the typespec files you want to generate off of. This allows us to have idempotence on generation until we opt into pointing at a later version. | true |
126+
| <a id="repo-anchor"></a> repo | The repo this spec lives in. This should be either `Azure/azure-rest-api-specs` or `Azure/azure-rest-api-specs-pr`. Note that pr will work locally but not in CI until we add another change to handle token based auth. | true |
110127

111128
Example:
112129

@@ -135,7 +152,6 @@ See the following example of a valid tspconfig.yaml file: https://github.com/Azu
135152

136153
Using the tspconfig.yaml linked above, by default, the client libraries will be generated in the following directory for C#: `<repo>/sdk/contosowidgetmanager/Azure.Template.Contoso/`.
137154

138-
139155
### emitter-package.json (Required)
140156

141157
`emitter-package.json` will be used the same as a `package.json` file. If the is no `emitter-package-lock.json` file, the tool will run `npm install` on the contents of `emitter-package.json`. This file allows each repository to pin the version of their emitter and other dependencies to be used when generating client libraries.
@@ -145,16 +161,16 @@ Example:
145161

146162
```json
147163
{
148-
"main": "dist/src/index.js",
149-
"dependencies": {
150-
"@azure-tools/typespec-csharp": "0.1.11-beta.20230123.1"
151-
}
164+
"main": "dist/src/index.js",
165+
"dependencies": {
166+
"@azure-tools/typespec-csharp": "0.1.11-beta.20230123.1"
167+
}
152168
}
153169
```
154170

155171
> NOTE: tsp compile currently requires the "main" line to be there.
156172

157-
> NOTE: This file replaces the package.json checked into the `azure-rest-api-spec` repository.
173+
> NOTE: This file replaces the package.json checked into the `azure-rest-api-spec` repository.
158174

159175
### emitter-package-lock.json (Optional)
160176

51 KB
Binary file not shown.

0 commit comments

Comments
 (0)