Skip to content

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

Notifications You must be signed in to change notification settings

hardtourvela/apiclientcodegen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

build status Version Installs Rating Quality Gate Status

REST API Client Code Generator

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

Features

  • Supports Visual Studio 2017 and 2019
  • Add New REST API Client to a project from an OpenAPI specification URL (e.g https://petstore.swagger.io/v2/swagger.json) using AutoRest, NSwag, Swagger Codegen, or OpenAPI Generator
  • Define custom namespace for the generated file
  • Auto-updating of generated code file when changes are made to the OpenAPI specification json file (Swagger.json)
  • Generate code using an NSwag Studio file by including it in the project and using the Generate with NSwag Studio context menu

Custom Tools

  • AutoRestCodeGenerator - Generates a single file C# REST API Client using AutoRest. The resulting file is the equivalent of using the AutoRest CLI tool with: --csharp --input-file=[swaggerFile] --output-file=[outputFile] --namespace=[namespace] --add-credentials

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

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

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

Dependencies

The custom tool code generators piggy back on top of well known Open API client code generators like AutoRest, NSwag, OpenAPI Generator, and Swagger Codegen. These tools require NPM, AutoRest, and the Java SDK 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 downloaded on demand but requires the Java SDK to be installed on the machine. This also means that using the SwaggerCodeGenerator and OpenApiCodeGenerator custom tools have a initial delay upon first time use. The generated code that these tools produce depends on the RestSharp v105.1.0 and JsonSubTypes v1.2.0 nuget packages.

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

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

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

Options - NSwag

Options - NSwag Studio

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 :)

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 96.1%
  • PowerShell 3.9%