Moji
Moji

Reputation: 1830

.Net Core2.2: Swagger not showing the UI

I have created an empty dotnet API and added the below NuGet package to my project:

<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1"/>

and this is my startup:

public class Startup {
    public Startup (IConfiguration configuration) {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices (IServiceCollection services) {
        services.AddMvc ().SetCompatibilityVersion (CompatibilityVersion.Version_2_2);
        services.AddSwaggerGen (c => {
            c.SwaggerDoc ("v1", new Info {
                Version = "v1",
                    Title = "My API",
                    Description = "My First ASP.NET Core Web API",
                    TermsOfService = "None",
                    Contact = new Contact () { Name = "Talking Dotnet", Email = "[email protected]", Url = "www.talkingdotnet.com" }
            });
        });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure (IApplicationBuilder app, IHostingEnvironment env) {
        if (env.IsDevelopment ()) {
            app.UseDeveloperExceptionPage ();
        } else {
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts ();
        }

        app.UseHttpsRedirection ();
        app.UseMvc ();
        app.UseSwagger ();
        app.UseSwaggerUI (c => {
            c.SwaggerEndpoint ("/swagger/v1/swagger.json", "My API V1");
        });
    }
}

but Swagger is not showing its UI and it looks like this: enter image description here

any ideas where the problem is?

Upvotes: 0

Views: 1470

Answers (1)

Ikram Shah
Ikram Shah

Reputation: 1246

You're browsing the json schema file

You should be browsing Swagger UI

by default it is https://youwebsite.com/swagger

here is a complete guide for Swahbuckle setup which i used

Get started with Swashbuckle

Upvotes: 2

Related Questions