Search code examples
c#code-generationnuget-packagenswag

Use Nswag Console (from NPM package) in order to generate C# client


According to the official Nswag command line docs it is possible to use Nswag via NPM console package (and subsquently generate C# client using openapi2cscontroller):

To use the command line tool nswag.exe (.NET 4.6+) / dotnet-nswag.dll (.NET Core), choose one of the following methods:

  • NSwag NPM Module: Bindings for the .NET 4.6+ and .NET Core command line tools (depending on installed framework/OS platform)

  • ...

Sadly, except for the link there is no further documentation in that matter. I have installed the package linked in the documentation (using npm install nswag --save-dev), it is however either broken or further undocumented steps are required:

> nswag new
> nswag : The term 'nswag' is not recognized as the name of a cmdlet, function, script file, or operable program.

Solution

  • You can install nswag as global:

    npm i -g nswag
    

    or use local package

    node_modules\.bin\nswag