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 or YAML file
- Generate code using an NSwagStudio specification file by including it in the project and using the Generate with NSwag 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.CSharpnuget package v13.10.9
SwaggerCodeGenerator - Generates a single file C# REST API Client using Swagger Codegen CLI v3.0.14.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 v5.1.0.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
A Visual Studio Code extension which will bring interactivity into your swagger documents! Ember-swagger-ui: An ember-cli addon for quickly and easily adding swagger-ui to your EmberJS application. Commandcar: cURL on steroids. Invoke any API from the commandline. SwagGen: Swift command line tool for generating client side code from a Swagger spec.
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 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. This means that using these custom tools have an initial delay upon first time use.
- Extension for Visual Studio Code - Swagger Viewer lets you preview and validate Swagger 2.0 and OpenAPI files as you type in Visual Studio Code.
- I like to add the code generation options directly to the Visual Studio project file. Right-click the project file of the.NET Core 5.0 Console Application and choose 'Edit Project File'. You will see a section that references the swagger. Json file we imported to generate the API client.
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 OpenAPI Generator and Swagger Codegen CLI code generators 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
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
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
Supports customising how AutoRest generates code based on the C# generator settings that the AutoRest CLI tool provides
Supports customising how NSwag generates code using the properties exposed by the NSwag NuGet package
Supports customising how the .nswag file is generated using a subset of the options available in NSwag Studio
This extension collects errors and tracks feature usages to a service called Exceptionless. This is done anonymously using a support key and a generated anonymous identity based on a secure hash of username@host
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 :)
This is a Visual Studio Code Extension that compares the Working Tree changes made to a Swagger 2.0
spec and shows the Breaking and other changes in a table format.
It will help Developers to know the impact of the changes they applied.
How To Use
To view the changes:
Open any Swagger 2.0 spec file with working changes
Open Command Palette (
ctrl
+shift
+p
)Run the command
Swagger Diff
The results will be shown in a new
WebViewPanel
To Copy the Output:
Click anywhere in the result panel
click
ctrl
+a
(orcmd
+a
for mac) to select all contentsclick
ctrl
+c
(orcmd
+c
for mac) to copy the contents
Add a keyboard shortcut for convenience, example:
Reading the Diff
There are 2 types of changes:
breaking change
smooth change
Breaking changes
Examples:
Delete path
Rename path operationId
Delete/Rename parametters
Add a constraint on a parametter (like isRequired)
Modify a response item
In the extension the breaking changes are considered as Error level
Smooth changes
Examples:
Add a path
Add a param
Add response item
Add/Update descriptions
In the extension the smooth changes are considered as Warning level
In some Scenarios the utility may be unable to categorize the change, they will be coming under UnCategorized level
Requirements
It works for Swagger 2.0 specs only
The file must be a part of a git repository
It will only compare the working tree changes, i.e changes made relative to the index (staging area for the next commit)
Release Notes
0.0.1
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 :)
This is a Visual Studio Code Extension that compares the Working Tree changes made to a Swagger 2.0
spec and shows the Breaking and other changes in a table format.
It will help Developers to know the impact of the changes they applied.
How To Use
To view the changes:
Open any Swagger 2.0 spec file with working changes
Open Command Palette (
ctrl
+shift
+p
)Run the command
Swagger Diff
The results will be shown in a new
WebViewPanel
To Copy the Output:
Click anywhere in the result panel
click
ctrl
+a
(orcmd
+a
for mac) to select all contentsclick
ctrl
+c
(orcmd
+c
for mac) to copy the contents
Add a keyboard shortcut for convenience, example:
Reading the Diff
There are 2 types of changes:
breaking change
smooth change
Breaking changes
Examples:
Delete path
Rename path operationId
Delete/Rename parametters
Add a constraint on a parametter (like isRequired)
Modify a response item
In the extension the breaking changes are considered as Error level
Smooth changes
Examples:
Add a path
Add a param
Add response item
Add/Update descriptions
In the extension the smooth changes are considered as Warning level
In some Scenarios the utility may be unable to categorize the change, they will be coming under UnCategorized level
Requirements
It works for Swagger 2.0 specs only
The file must be a part of a git repository
It will only compare the working tree changes, i.e changes made relative to the index (staging area for the next commit)
Release Notes
0.0.1
Initial release
Visual Studio Code Swagger Editor
Credits
Visual Studio Code Swagger Code
Swagger Viewer utilizes the following open source projects