Daan
Daan

Reputation: 2928

How to show the full swagger interface when using NSwag with .NET 5?

I am trying to familiarize with NSwag usage for .NET 5 as documented here. After reading, I got the impression that this documentation is outdated as it mentions methods such as UseMvc and AddMvc which are typical for .NET Core 2.1 but not for .NET 5. Anyway, here are my Configure methods (I manipulated the standard .NET 5 Web Api project automatically generated by Visual Studio 2019):

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddSwaggerDocument();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseOpenApi();
    app.UseSwaggerUi3();
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
    });
}

After pressing F5, the following was shown:

enter image description here

This is the project file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NSwag.AspNetCore" Version="13.11.3" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
  </ItemGroup>

</Project>

Apparently, I "lost" the GET method of the WeatherForecastController. So, how to show the full swagger interface when using NSwag with .NET 5? The code examples referred to by the docs, are not helping me either as these are based on old versions of .NET Core. The reason for me to use NSwag is that is "the most popular tool for the job" to generate typescript code for my client projects.

Upvotes: 0

Views: 850

Answers (1)

Laksmono
Laksmono

Reputation: 690

Click the WeatherForecast to expand the node to see the details, you will find the GET Method there.

Upvotes: 2

Related Questions