0

I am using nswag to generate the swagger. However the openapi json file is only in memory, you can only access it by starting the application and navigate to the link swagger/v1/swagger.json.

I want the json file to be generated and save physically in the project after every build. How should I achieved this?

1 Answers1

0

Create an nswag.json configuration file in root of project, and specify in it e.g. "output": "swagger.json". See documentation of nswag.json here: https://github.com/RicoSuter/NSwag/wiki/NSwag-Configuration-Document

Then add something like this to your .csproj file to have it run on building the project:

<Target Name="NSwag" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' ">
    <Exec WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" Command="$(NSwagExe_Net60) run nswag.json /variables:Configuration=$(Configuration)" />
</Target>

See documentation here: https://github.com/RicoSuter/NSwag/wiki/NSwag.MSBuild

Jeppe
  • 1,830
  • 3
  • 24
  • 33