Search code examples
c#visual-studio-2019nswagstudio

Can we configure NSwagCSharp code generator in visualstudio csproj project file?


NSwagStudio provide us with lots of settings to get a custom auto-generated swagger client in C#.

But when we use VisualStudio 2019 Solution Explorer and open the "Connected Services" on a project, we can add an OpenAPI service from a swagger json file, but I don't see any way to configure the code generator. So that you have a default one.

Is it possible to configure NSwagCSharp code generator in visualstudio csproj project file for example ?


Solution

  • We can just fill in the 'Additional code generation options' of the wizard using the "NSwag Command Line" syntax, i.e. : /generateDtoTypes:false /injectHttpClient:true

    Refer to the list of possible options on https://github.com/RicoSuter/NSwag/wiki/NSwag-Configuration-Document under section "openApiToCSharpClient".

    This is also explained well on the blog: https://stevetalkscode.co.uk/openapireference-commands