I had a “WTHek” time installing Swagger, the documentation tool.
- Info class not found
- Failed to fetch http://myserver/v1/swagger.json
Solution
So here is how to install Swagger in the right way.
Create a new Web API project.
Create a new Web API project in .Net Core 2.2
Ensure it is compiling fine.
Run Package Manager
Go to your Web API project & Run Package Manager command
Install-Package Swashbuckle.AspNetCore -Version 5.0.0-rc4
Install-Package Microsoft.OpenApi.Models
Add Code to ConfigureServices() method
Towards the last.
services.AddSwaggerGen(c =>
{
c.SwaggerDoc(“v1”, new OpenApiInfo { Title = “My API”, Version = “v1” });
});
// Resolve namespace for OpenApiInfo
Add Code to Configure() method
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint(“/swagger/v1/swagger.json”, “API V1”);
});
Run the Application
You should be able to access the Swagger documentation as below:
More Debugging
If you missed any [HttpGet] attributes also swagger will give above “swagger.json” error.
Open the Output window to view which Controller method is causing trouble.