Visual Studio Code Swagger



Swagger Codegen Swagger Codegen can simplify your build process by generating server stubs and client SDKs for any API, defined with the OpenAPI (formerly known as Swagger) specification, so your team can focus better on your API’s implementation and adoption. SwaggerCodeGenerator - Generates a single file C# REST API Client using Swagger Codegen CLI v3.0.14. See screenshot below. I now have an updated version of the Swagger file and need to also update the auto-generated client code. How do I do this in Visual Studio? I have not been able to find a way to update the auto-generated code without completely deleting the code.

SwaggerHub Extension for Visual Studio Code The SwaggerHub extension lets you view and edit your OpenAPI definitions stored in SwaggerHub directly from Visual Studio Code. You can access your organization's APIs and domains and sync the changes back to SwaggerHub. Both SwaggerHub SaaS and On-Premise are supported.

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

Features

Visual Studio Code Swagger Free

  • 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

Swagger Tutorial Visual Studio

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 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.

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

Swagger Studio Download

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

Visual Studio Code Swagger Html

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

Visual studio swagger codegenVisual

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

Visual Studio Code Swagger

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

A VSCode extension that scaffolds openAPI (swagger) specs from your editor.Get it on the VSCode Marketplace.

Got any feedback, issues or feature requests? Send them my way via GitHub Issues.

  • Swagger Tools
    • Features
    • Upcoming Features
    • Author

See the CHANGELOG for the latest changes.

Commands

Command nameDescriptionShortcut
swagger-tools.pasteSchemaGenerates an openAPI schema from an object or array in the clipboardctrl/cmd + alt + v
swagger-tools.addComponentAdds an openAPI schema into the components spec field (optionally generated from clipboard)ctrl/cmd + alt + c

Settings

Settings → Extensions → Swagger Tools

SettingDescriptionAllowed Values
swagger-tools.arrayTypeSpecify the type of array you want auto generated'anyOf', 'oneOf', 'allOf', 'not'

Features

Generate & Paste Schema Object

  1. Copy the object or array you would like to generate
  2. Go to the desired openAPI spec file
  3. Place your cursor where you would like to paste your schema
  4. Paste by typing the macro ctrl/cmd + alt + v

Generate Components

Select from a list of components to generate fully scaffolded schemas.The schemas will be auto inserted in its proper field.

  • Schemas

  1. Copy the object or array you would like to generate as a component schema
  2. Go to the desired openAPI spec file
  3. Paste by typing the macro ctrl/cmd + alt + c
  4. Fill out schema info in command pallette

Upcoming Features

The upcoming features list is order by expected release date...

Scaffold New Spec

An easy and quick set up for anyone on the team.

  • Scaffold a new spec from scratch
  • Choose between a complex or basic spec

Generate Components Continued...

Select from a list of components to generate fully scaffolded schemas.The schemas will be auto inserted in its proper field.

Upcoming Releases:

  • responses
  • parameters
  • examples
  • requestBodies
  • headers
  • securitySchemes
  • links
  • callbacks

Generate Paths

Fully generate paths with all their required fields.

  • GET, POST, PUT, PATCH, DELETE

More to come...

  • Auto populate paths with request bodies, params, responses, etc...
  • Linting
  • Error decorators

Author

Created and sustained by Aaron Turkel (a.k.a. The Holy Coder).

Contributors

Have an idea that could make Swagger Tools better? Contribute!