1

I have installed Swashbuckle.AspNetCore version 4.0.1 and tried all solutions and ways. Maybe this is duplicate it's not working in IIS.
I always get not found error or internal server error.
This is my Startup.cs.

// Configure Services
services.AddSwaggerGen(x =>
{
    x.SwaggerDoc("v1", new Info { Title = "Shop API", Version = "v1" });
});

  // Configure
  app.UseSwagger();

  app.UseSwaggerUI(c =>
        {
  c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
      //c.RoutePrefix = string.Empty;
  });

  app.UseMvc();

Did anybody tried latest version?

1 Answer 1

2

I'm using the same version as your. Mine below config look like this

ConfigureServices

// Register the Swagger generator, defining one or more Swagger documents
            services.AddMvc();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version = "v1",
                    Title = "Awesome CMS Core API V1",
                    Contact = new Contact { Name = "Tony Hudson", Email = "", Url = "https://github.com/ngohungphuc" }
                });

                c.SwaggerDoc("v2", new Info
                {
                    Version = "v2",
                    Title = "Awesome CMS Core API V2",
                    Contact = new Contact { Name = "Tony Hudson", Email = "", Url = "https://github.com/ngohungphuc" }
                });

                c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
            });

Configure

    // Enable middleware to serve generated Swagger as a JSON endpoint.
    app.UseSwagger();

    // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint($"/swagger/v1/swagger.json", "Awesome CMS Core API V1");
        c.SwaggerEndpoint($"/swagger/v2/swagger.json", "Awesome CMS Core API V2");
    });

   app.UseMvc(routes =>
   {
     routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
     });
   }

I'm just having 2 API version so it's not important in your case

Make sure your middleware are in correct order like mine

Please let me know if you have any problem

2
  • Thank you for your answer. It was from one of my actions. it had Route attribute and swagger didn't catch it. Commented May 3, 2019 at 18:40
  • c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); solved the problem for me. Commented Oct 10, 2019 at 2:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.