Search code examples
swaggeropenapirider

Rider: How to generate a OpenApi (Swagger) web service reference?


With Unchase.OpenApi exists a Visual Studio Extension to generate code for web services with NSwag.

Annimation

This leads me to the following question: Is there a way to create a web service reference based on a swagger.json reference in Rider?


Solution

  • I haven't used the extension. Based on the gif I conclude, it generates clients one time and then the generated code is commited. We use in our project another approach.

    1. Add an OpenAPI reference to the csproj file

       <OpenApiReference Include="..\relative\path\to\openapi.json" CodeGenerator="NSwagCSharp" ClassName="{controller}Client" Link="OpenAPIs\openapi.json" />
      
    2. Reference the package NSwag.ApiDescription.Client

    3. The client(s) will be generated before building the project and placed in obj directory. Since that they are available to use in your code.