• Stars
    star
    167
  • Rank 226,635 (Top 5 %)
  • Language
    C#
  • License
    GNU General Publi...
  • Created almost 6 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collection of Visual Studio custom tool code generators for Swagger / OpenAPI specification files

Build status CLI Tool VSIX VS Mac Smoke Tests

Maintainability Rating Reliability Rating Security Rating Bugs Vulnerabilities Code Smells Coverage

Version Downloads Rating Downloads Rating NuGet NuGet

buymeacoffee Join the chat at https://gitter.im/apiclientcodegen/community

REST API Client Code Generator

A collection of Visual Studio C# custom tool code generators for Swagger / OpenAPI specification files

Download

Features

Custom Tools

  • NSwagCodeGenerator - Generates a single file C# REST API Client using the NSwag.CodeGeneration.CSharp nuget package v13.19.0

  • OpenApiCodeGenerator - Generates a single file C# REST API Client using OpenAPI Generator v7.0.0-beta. The output file is the result of merging all the files generated using the OpenAPI Generator tool with: generate -g csharp --input-spec [swagger file] --output [output file] -DapiTests=false -DmodelTests=false -DpackageName=[default namespace] --skip-overwrite

  • KiotaCodeGenerator - Generates a single file C# REST API Client using the Microsoft project Kiota v1.4.0 generator. The output file is the result of merging all the files generated using the Kiota dotnet tool with: generate -l CSharp -d [swagger file] -o [output file] -n [default namespace]

  • SwaggerCodeGenerator - Generates a single file C# REST API Client using Swagger Codegen CLI v3.0.34. The output file is the result of merging all the files generated using the Swagger Codegen CLI tool with: generate -l csharp --input-spec [swagger file] --output [output file] -DapiTests=false -DmodelTests=false -DpackageName=[default namespace] --skip-overwrite

  • AutoRestCodeGenerator - Generates a single file C# REST API Client using AutoRest v3.0.0-beta.20210504.2 for OpenAPI v3 and AutoRest v2.0.4417 for OpenAPI v2. The resulting file is the equivalent of using the AutoRest CLI tool with:+ --csharp --input-file=[swagger file] --output-file=[output file] --namespace=[default namespace] --add-credentials

  • RefitterCodeGenerator - Generates a single file C# REST API Client inteface for Refit using Refitter.Core nuget package v0.6.2. The output file contains a Refit interface generated by Refitter and contracts generated using NSwag.CodeGeneration.CSharp nuget package

Dependencies

The custom tool code generators piggy back on top of well known Open API client code generators like AutoRest, NSwag, OpenAPI Generator, Project Kiota, Refitter, and Swagger Codegen CLI. These tools require NPM and the Java Runtime Environment to be installed on the developers machine. Alternative Java SDK implementations such as the OpenJDK works fine with this extension. By default, the path to java.exe is read from the JAVA_HOME environment variable, but is also configurable in the Settings screen

The Swagger Codegen CLI and OpenAPI Generator are distributed as JAR files and are downloaded on demand but requires the Java SDK to be installed on the machine. AutoRest is installed on-demand via NPM as a global tool and uses the latest available version. Project Kiota is installed on-demand as a .NET Tool and requires .NET 7.0. This means that using these custom tools have an initial delay upon first time use.

NSwagStudio is stand alone UI tool for editing a .nswag specification file for generating code. This tool is optional to install and official installation instructions are available on the NSwag Wiki on Github. If NSwagStudio is not installed on the machine then the Visual Studio Extension will install the NSwag CLI via NPM as a global tool using the latest available version.

The NSwag code generator produces code that depends on the Newtonsoft.Json NuGet package

The Refitter code generator produces code that depends on the Refit NuGet package

The OpenAPI Generator code generator produces code that depends on the following NuGet packages:

The project Kiota code generator produces code that depends on the following NuGet packages

The Swagger Codegen CLI code generator produces code that depends on the RestSharp and JsonSubTypes NuGet packages

The AutoRest code generator produces code that depends on the Microsoft.Rest.ClientRuntime and Newtonsoft.Json NuGet packages

This Visual Studio Extension will automatically add the required NuGet packages that the generated code depends on

Screenshots

Add - API Client from OpenAPI Specification

Enter URL to OpenAPI Specification

Solution Explorer Context Menus

NSwag Studio Context Menu

Settings

This extension will by default make some assumptions on the installation paths for Java, NSwag and NPM but also provides option pages for configuring this. The Swagger Codegen CLI and the OpenAPI Generator JAR files are by default downloaded to the user TEMP folder but it is also possible to specify to use existing JAR files

Options - General

Supports customising how AutoRest generates code based on the C# generator settings that the AutoRest CLI tool provides

Options - AutoRest

Supports customising how NSwag generates code using the properties exposed by the NSwag NuGet package

Options - NSwag

Supports customising how the .nswag file is generated using a subset of the options available in NSwag Studio

Options - NSwag Studio

Supports customising how OpenAPI Generator generates code using the additional optional properties that the OpenAPI Generator CLI tool provides

Options - OpenAPI Generator

Supports customising how Refitter generates the Refit interface. This allows you to configure whether to return the type directly or wrap it inside an IApiResponse<T>. You can also disable generating contracts or XML doc style comments

Options - Refitter

This extension collects errors and tracks feature usages to a service called Exceptionless and Azure Application Insights. This is done anonymously using a support key and a generated anonymous identity based on a secure hash of username@host

Options - Analytics

Visual Studio for Mac

Add - API Client from OpenAPI Specification

Enter URL to OpenAPI Specification

Solution Explorer Context Menus

NSwag Studio Context Menu

Installation

The Visual Studio extension can be installed directly from Visual Studio 2019 and 2022 via the Extensions Dialog Box. The process is best described in the official Microsoft documentation for Managing extensions for Visual Studio

Visual Studio for Mac

This installation process for Visual Studio for Mac is currently a bit troublesome as the MonoDevelop Addin Repository is currently not accepting new users so I can't really register and setup my extension.

There are 2 ways of installing my extension on Visual Studio for Mac: Adding a custom extension repository or Installing the .mpack file directly from the Extensions Manager

Adding a new extension repository

Here's what you need to do:

  • Open the Visual Studio for Mac Extension Manager
  • You can do this from the menu Visual Studio -> Extentions

Open Extensions Dialog Box

  • Select the Gallery Tab
  • Expand the Repository drop down box and select Manage Repositories

Manage Repositories

  • Press on the Add button to add a new custom extension repository

Manage Repositories

Add Repository

  • Now my extension repository is added to the list
  • Make sure that this is enabled (indicated by a check box)

Add Repository Dialog

  • You should now be able to see my extensions from the Gallery tab

Added Repository

  • By adding my extension repository you will be able to conveniently update my extension using the Visual Studio for Mac Extension Manager

Add Repository

Add Repository

Add Repository

Installing the .mpack file directly

Here's what you need to do:

  • Download the latest .mpack file from the Latest Github Release
  • Now from within Visual Studio for Mac you need to launch the Extensions Dialog Box. You can do this from the menu Visual Studio -> Extentions

Open Extensions Dialog Box

  • Click on the Install from File button

Manually install .mpack file

  • Browse to the .mpack file and select it. You will be prompted with a confirmation dialog

Confirm .mpack file install

  • Click Install and restart Visual Studio for Mac

  • To Verify that the Add-in was installed you can re-open the Extensions Dialog Box, select the Installed tab and expand the IDE Extensions. You should be able to see the REST API Client Code Generator.

  • Uninstalling the Add-in is done in this same dialog box by clicking the Uninstall button

Manually uninstall Add-in

Cross Platform Command Line Tool

All custom tools mentioned above are also implemented in a cross platform command line application

Requirements

  • .NET 6.0 runtime
  • Java Runtime Environment
  • NPM

Installation

The tool can be installed as a .NET Core global tool that you can call from the shell / command line

dotnet tool install --global rapicgen

or by following the instructions here to install a specific version of tool

Usage

Since the tool is published as a .NET Core Tool, it can be launched from anywhere using any command line interface by calling rapicgen. The help information is displayed when not specifying any arguments to rapicgen

Usage: rapicgen [command] [options]

Options:
  -v|--verbose       Show verbose output
  -?|-h|--help       Show help information.

Commands:
  csharp             Generate C# API clients
  jmeter             Generate Apache JMeter test plans
  openapi-generator  Generate code using OpenAPI Generator (v7.0.0-beta).
                     See supported generators at https://openapi-generator.tech/docs/generators/
  typescript         Generate TypeScript API clients

Run 'rapicgen [command] -?|-h|--help' for more information about a command.

Some help information is also provided per command and can be launched by

rapicgen [command name] -?

or

rapicgen [command name] [sub command name] -?

For example:

rapicgen csharp -?

will output this:

Generate C# API clients

Usage: rapicgen csharp [command] [options]

Options:
  -?|-h|--help  Show help information.

Commands:
  autorest      AutoRest (v3.0.0-beta.20210504.2)
  kiota         Microsoft project Kiota (v1.4.0)
  nswag         NSwag (v13.19.0)
  openapi       OpenAPI Generator (v7.0.0-beta)
  refitter      Refitter (v0.6.2)
  swagger       Swagger Codegen CLI (v3.0.34)

Run 'csharp [command] -?|-h|--help' for more information about a command.

and

rapicgen csharp autorest -?

will output this:

Generate Swagger / Open API client using AutoRest

Usage: run autorest [options] <swaggerFile> <namespace> <outputFile>

Arguments:
  swaggerFile   Path to the Swagger / Open API specification file
  namespace     Default namespace to in the generated code
  outputFile    Output filename to write the generated code to. Default is the swaggerFile .cs

Options:
  -?|-h|--help  Show help information

or

rapicgen typescript -?

will output this:

Generate TypeScript API client

Usage: rapicgen typescript [options] <generator> <swaggerFile> <outputPath>

Arguments:
  generator         The tech stack to use for the generated client library
                    Allowed values are: Angular, Aurelia, Axios, Fetch, Inversify, JQuery, NestJS, Node, ReduxQuery,
                    Rxjs.
                    Default value is: Angular.
  swaggerFile       Path to the Swagger / Open API specification file
  outputPath        Output folder to write the generated code to
                    Default value is: typescript-generated-code.

Options:
  -nl|--no-logging  Disables Analytics and Error Reporting
  -?|-h|--help      Show help information.

Usage Examples:

Let's say we have a OpenAPI Specifications document called Swagger.json

For starters, we can use the Swagger Petstore spec. Here's an example powershell script for downloading it

Invoke-WebRequest -Uri https://petstore.swagger.io/v3/swagger.json -OutFile Swagger.json

In case you don't have the CLI tool installed you can install it by

dotnet tool install --global rapicgen

Here's an example of how to generate code using AutoRest

rapicgen csharp autorest Swagger.json GeneratedCode ./AutoRestOutput.cs

Here's an example of how to generate code using Kiota

rapicgen csharp kiota Swagger.json GeneratedCode ./OpenApiOutput.cs

Here's an example of how to generate code using NSwag

rapicgen csharp nswag Swagger.json GeneratedCode ./NSwagOutput.cs

Here's an example of how to generate code using Swagger Codegen CLI

rapicgen csharp swagger Swagger.json GeneratedCode ./SwaggerOutput.cs

Here's an example of how to generate code using OpenAPI Generator

rapicgen csharp openapi Swagger.json GeneratedCode ./OpenApiOutput.cs

Here's an example of how to generate code JMeter test plans

rapicgen jmeter Swagger.json

Here's an example of how to generate code for TypeScript

rapicgen typescript Angular Swagger.json

For tips and tricks on software development, check out my blog

If you find this useful and feel a bit generous then feel free to buy me a coffee β˜•

More Repositories

1

refitter

A tool for generating Refit interfaces and contracts from OpenAPI specifications
C#
170
star
2

httpgenerator

Generate .http files from OpenAPI (Swagger) specifications
C#
71
star
3

sqlcequery

A fast and lightweight tool for querying and manipulating SQLCE databases. This tool supports SQLCE versions 3.0, 3.1, 3.5 and 4.0
ANTLR
49
star
4

reswcodegen

A Visual Studio Custom Tool for generating a strongly typed helper class for accessing localized resources from a .ResW file.
C#
11
star
5

ScrollableSegmentedControl

A drop-in replacement for UISegmentedControl mimicking the style of the segmented control used in Google Currents and various other Google products.
C#
10
star
6

BarcodeScannerFactory

A simplified abstraction over a collection of barcode scanner SDK's and supports device detection. Supports the following device: Intermec, Motorola, Symbol, and Casio
C#
9
star
7

appcenterextensions

A set of convenience classes and extension methods to simplify Crash Reporting and Analytics using AppCenter
C#
7
star
8

autofaker

Python library designed to minimize the setup/arrange phase of your unit tests
Python
6
star
9

gfic

A .NET Core based command line image processor written in F#
F#
4
star
10

christianhelle.github.io

https://christianhelle.com
C#
2
star
11

SocketHttp

Fast Socket based HTTP Client as an alternative to WebClient
C#
2
star
12

curlgenerator

Generate cURL Requests from OpenAPI (Swagger) specifications
C#
2
star
13

sqlcecodegen

Contains a stand alone GUI application and a Visual Studio Custom Tool for automatically generating a .NET data access layer code for objects in a SQL Server Compact Edition database.
Inno Setup
2
star
14

jmetercodegen

Generate JMeter Test Plans from ASP.NET Core Web API's
C#
1
star
15

playwright-experiments

C#
1
star
16

xamarin-memory-management-demo

Demos from the presentation entitled Xamarin Memory Management
C#
1
star
17

mobfx

C#
1
star
18

azure-cli-scripts

A collection of Azure CLI to solve common problems
PowerShell
1
star
19

xnapuzzlegame

(Legacy) A simple XNA based puzzle game for Windows Phone 7
C#
1
star
20

VisualStudioLauncher

Launch Visual Studio with a theme that matches the time of day (Light mode during day, Dark mode at night)
C#
1
star
21

apiclientcodegen-vsmac

This is a Visual Studio for Mac extension repository for REST API Client Code Generator
HTML
1
star
22

demo-appinsights

C#
1
star
23

vsmac-extensions-repo

HTML
1
star