Skip to content

Latest commit

 

History

History
156 lines (93 loc) · 10.4 KB

VisualStudioForMac.md

File metadata and controls

156 lines (93 loc) · 10.4 KB

REST API Client Code Generator

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

Features

Custom Tools

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

  • OpenApiCodeGenerator - Generates a single file C# REST API Client using OpenAPI Generator v7.7.0. 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.16.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 v1.1.1. 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, Microsoft 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. Microsoft 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

NOTE: Visual Studio for Mac version currently installs missing NuGet packages via the dotnet CLI tool

Screenshots

Add - API Client from OpenAPI Specification

Enter URL to OpenAPI Specification

Solution Explorer Context Menus

NSwag Studio Context Menu

Installation

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



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