Skip to content
Rico Suter edited this page Aug 2, 2016 · 34 revisions

To use the command line tool nswag.exe, choose one of the following methods:

The NSwag.exe command line tool

To see all available commands and parameters, run the command line application "nswag.exe" without parameters and enter "help" as command. All "input" parameters accept file paths, URLs and JSON data.

Run .nswag configuration file

You can run a .nswag configuration file by using the run command:

nswag run MySwaggerConfig.nswag

To run all .nswag configuration files in the current directory use the run command without parameters:

nswag run

Swagger Generators

To generate a Swagger specification from a Web API controller in a .NET assembly, see WebApiToSwaggerGenerator for more information:

nswag webapi2swagger /assembly:MyWebApiAssembly.dll 
                     /controller:MyNamespace.MyController 
                     /output:MyWebService.json

To generate a single Swagger specification for all controllers in the assembly, just call the command without the controller parameter:

nswag webapi2swagger /assembly:MyWebApiAssembly.dll 
                     /output:MyWebService.json

The assembly parameter accepts multiple assemblies separated with a comma, e.g. /assembly:a1.dll,a2.dll.

WebApiToSwaggerCommand.cs

Client Generators

Generate TypeScript client code from a Swagger specifiation, see SwaggerToTypeScriptClientGenerator for more information:

nswag swagger2tsclient /input:MyWebService.json 
                       /output:MyModule.ts

SwaggerToTypeScriptClientCommand.cs

Generate C# client code from a Swagger specifiation, see SwaggerToCSharpClientGenerator:

nswag swagger2csclient /input:MyWebService.json 
                       /classname:MyServiceClient 
                       /namespace:MyNamespace
                       /output:MyServiceClient.cs

SwaggerToCSharpClientCommand.cs

Generate Swagger from .NET types

Generate a Swagger specification describing only the given .NET types:

nswag types2swagger /assembly:MyAssembly.dll
                    /classnames:MyNamespace.Person,MyNamespace.Car 
                    /output:MySwagger.json

AssemblyTypeToSwaggerCommand.cs

JSON Schema converters

Generate C# classes from a JSON Schema:

nswag jsonschema2csclient /input:JsonSchema.json 
                          /output:MyClasses.cs

JsonSchemaToCSharpCommand.cs

Generate TypeScript interfaces from a JSON Schema:

nswag jsonschema2tsclient /input:JsonSchema.json 
                          /output:MyInterfaces.ts

JsonSchemaToTypeScriptCommand.cs

Clone this wiki locally