|
1 |
| -This VS Code extension is a cross-platform alternative to the Visual Studio extension for generating C# REST API clients from OpenAPI/Swagger specifications. |
| 1 | +[](https://www.buymeacoffee.com/christianhelle) |
| 2 | + |
| 3 | +There is a separate VSIX installer available for **[Visual Studio 2022](https://marketplace.visualstudio.com/items?itemName=ChristianResmaHelle.ApiClientCodeGenerator2022)**, **[Visual Studio 2019](https://marketplace.visualstudio.com/items?itemName=ChristianResmaHelle.APIClientCodeGenerator)** and **[Visual Studio 2017](https://marketplace.visualstudio.com/items?itemName=ChristianResmaHelle.ApiClientCodeGenerator2017)** |
| 4 | + |
| 5 | +# REST API Client Code Generator |
| 6 | + |
| 7 | +A VS Code extension for generating C# and TypeScript REST API clients from OpenAPI/Swagger specifications. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +You can install this extension in several ways: |
| 12 | + |
| 13 | +1. **VS Code Marketplace**: Search for "REST API Client Code Generator" in the VS Code Extensions view. |
| 14 | + |
| 15 | +2. **Manual Installation**: |
| 16 | + - Download the `.vsix` file from the [GitHub releases page](https://github.com/christianhelle/apiclientcodegen/releases) |
| 17 | + - In VS Code, go to Extensions view |
| 18 | + - Click on "..." menu in the top right corner |
| 19 | + - Select "Install from VSIX..." |
| 20 | + - Locate and select the downloaded `.vsix` file |
| 21 | + |
| 22 | +3. **Build from Source**: |
| 23 | + |
| 24 | + ```powershell |
| 25 | + git clone https://github.com/christianhelle/apiclientcodegen.git |
| 26 | + cd apiclientcodegen |
| 27 | + ./src/build-vscode.ps1 |
| 28 | + ``` |
| 29 | + |
| 30 | + Then install the generated `.vsix` file using the method above. |
2 | 31 |
|
3 | 32 | ## Features
|
4 | 33 |
|
5 |
| -- Generate C# REST API clients from OpenAPI/Swagger JSON or YAML files |
6 |
| -- Context menu integration on JSON and YAML files in the VS Code explorer |
7 |
| -- Support for all code generators: |
8 |
| - - NSwag |
9 |
| - - Refitter |
10 |
| - - OpenAPI Generator |
11 |
| - - Microsoft Kiota |
12 |
| - - Swagger Codegen CLI |
13 |
| - - AutoREST |
14 |
| -- Configuration options for namespace and output directory |
15 |
| -- Cross-platform support (Windows, macOS, Linux) |
| 34 | +This extension adds a context menu item **REST API Client Code Generator** when right-clicking on JSON or YAML files in the VS Code explorer. The context menu provides the following code generation options: |
| 35 | + |
| 36 | +### C# Generators |
| 37 | + |
| 38 | +- **NSwag**: Generates a C# REST API Client using NSwag |
| 39 | +- **Refitter**: Generates a C# Refit interface using Refitter |
| 40 | +- **OpenAPI Generator**: Generates a C# REST API Client using OpenAPI Generator |
| 41 | +- **Microsoft Kiota**: Generates a C# REST API Client using Microsoft Kiota |
| 42 | +- **Swagger Codegen CLI**: Generates a C# REST API Client using Swagger Codegen CLI |
| 43 | +- **AutoREST**: Generates a C# REST API Client using AutoREST |
| 44 | + |
| 45 | +### TypeScript Generators |
| 46 | + |
| 47 | +- **Angular**: Generates a TypeScript REST API Client for Angular |
| 48 | +- **Aurelia**: Generates a TypeScript REST API Client for Aurelia |
| 49 | +- **Axios**: Generates a TypeScript REST API Client for Axios |
| 50 | +- **Fetch**: Generates a TypeScript REST API Client for Fetch |
| 51 | +- **Inversify**: Generates a TypeScript REST API Client for Inversify |
| 52 | +- **jQuery**: Generates a TypeScript REST API Client for jQuery |
| 53 | +- **NestJS**: Generates a TypeScript REST API Client for NestJS |
| 54 | +- **Node**: Generates a TypeScript REST API Client for Node |
| 55 | +- **Redux Query**: Generates a TypeScript REST API Client for Redux Query |
| 56 | +- **RxJS**: Generates a TypeScript REST API Client for RxJS |
16 | 57 |
|
17 | 58 | ## Screenshot
|
18 | 59 |
|
19 | 60 | 
|
20 | 61 |
|
21 |
| - |
| 62 | + |
22 | 63 |
|
23 |
| - |
| 64 | + |
24 | 65 |
|
25 | 66 | ## Requirements
|
26 | 67 |
|
27 |
| -- .NET 6.0 SDK or higher |
| 68 | +### For C# code generation |
| 69 | + |
| 70 | +- .NET SDK 6.0 or higher |
28 | 71 | - Java Runtime Environment (for OpenAPI Generator and Swagger Codegen CLI)
|
29 | 72 | - NPM (for AutoREST and NSwag)
|
30 | 73 |
|
| 74 | +### For TypeScript code generation |
| 75 | + |
| 76 | +- Node.js and NPM |
| 77 | +- OpenAPI Generator |
| 78 | + |
31 | 79 | The extension uses the `rapicgen` .NET tool to generate the code. If not already installed, you will be prompted to install it when first attempting to generate code.
|
32 | 80 |
|
33 |
| -## Usage |
| 81 | +## Settings and Configuration |
| 82 | + |
| 83 | +The extension includes configurable settings: |
| 84 | + |
| 85 | +- `restApiClientCodeGenerator.namespace`: Default namespace to use in generated code (default: "GeneratedCode") |
| 86 | +- `restApiClientCodeGenerator.outputDirectory`: Output directory relative to workspace folder (default: same directory as the specification file) |
| 87 | + |
| 88 | +## How to Use |
34 | 89 |
|
35 | 90 | 1. Right-click on a Swagger/OpenAPI specification file (JSON or YAML) in the VS Code explorer
|
36 |
| -2. Select "REST API Client Code Generator" in the context menu |
37 |
| -3. Choose one of the available code generators |
38 |
| -4. The generated C# code will be opened in the editor |
| 91 | +2. Select "REST API Client Generator" in the context menu |
| 92 | +3. Choose your desired language (C# or TypeScript) |
| 93 | +4. Select one of the available generators for that language |
| 94 | +5. The generated code will be saved in the configured output directory and opened in the editor |
39 | 95 |
|
40 |
| -## Extension Settings |
| 96 | +## Dependencies |
41 | 97 |
|
42 |
| -This extension contributes the following settings: |
| 98 | +### C# Dependencies |
43 | 99 |
|
44 |
| -* `restApiClientCodeGenerator.namespace`: Default namespace to use in generated code (default: "GeneratedCode") |
45 |
| -* `restApiClientCodeGenerator.outputDirectory`: Output directory relative to workspace folder (default: same directory as the specification file) |
| 100 | +The C# code generated by each generator depends on different NuGet packages: |
46 | 101 |
|
47 |
| -## Installation |
| 102 | +- **NSwag**: Depends on Newtonsoft.Json |
| 103 | +- **Refitter**: Depends on Refit |
| 104 | +- **OpenAPI Generator**: Depends on RestSharp, JsonSubTypes, Polly, Newtonsoft.Json |
| 105 | +- **Microsoft Kiota**: Depends on Microsoft.Kiota.* packages and Azure.Identity |
| 106 | +- **Swagger Codegen CLI**: Depends on RestSharp and JsonSubTypes |
| 107 | +- **AutoREST**: Depends on Microsoft.Rest.ClientRuntime and Newtonsoft.Json |
48 | 108 |
|
49 |
| -You can install this extension in several ways: |
| 109 | +### TypeScript Dependencies |
50 | 110 |
|
51 |
| -1. Download the VSIX from [GitHub Releases](https://github.com/christianhelle/apiclientcodegen/releases) |
52 |
| -2. Install from VSIX in VS Code: |
53 |
| - - Go to Extensions view (Ctrl+Shift+X) |
54 |
| - - Click "..." menu in the top right corner |
55 |
| - - Select "Install from VSIX..." |
56 |
| - - Select the downloaded .vsix file |
| 111 | +The TypeScript code generated depends on the framework chosen: |
| 112 | + |
| 113 | +- **Angular**: Depends on @angular/core, rxjs |
| 114 | +- **Axios**: Depends on axios |
| 115 | +- **Fetch**: Uses the browser's native fetch API |
| 116 | +- **jQuery**: Depends on jquery |
| 117 | +- **RxJS**: Depends on rxjs |
| 118 | +- For other frameworks, please refer to their official documentation or the [OpenAPI Generator documentation](https://openapi-generator.tech/docs/generators) for detailed dependency information. |
| 119 | + |
| 120 | +## Related |
| 121 | + |
| 122 | +- This extension is the VS Code equivalent of the [REST API Client Code Generator](https://marketplace.visualstudio.com/items?itemName=ChristianResmaHelle.APIClientCodeGenerator2022) extension for Visual Studio. |
0 commit comments