0
I am trying to implement Swagger in my application but I got the error by uploading the application
I did it by following the microsoft documentation, but, I did not succeed. It seems a very generic error, so I ask for help. Here’s my Swagger configuration class:
public static class SwaggerConfig
{
public static IServiceCollection AddSwaggerConfig(this IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
{
Version = "v1",
Title = "TestApi",
Description = "Primeira versão da API"
});
});
return services;
}
public static IApplicationBuilder UseSwaggerConfig(this IApplicationBuilder app)
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("swagger.json", "v1");
});
return app;
}
}
My Startup:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers();
services.AddSwaggerConfig();
..
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseCors("MyPolicy");
app.UseSwaggerConfig();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
What happens when you try to access https:/localhost:5001/Swagger/Swagger.json from the browser?
– Jéf Bueno
HTTP ERROR 404
– Henrique
what it looks like is that he is looking for Swagger.json on the /Swagger/Swagger.json path, but in c.swaggerEndpoint you just marked "Swagger.json"
– Lucas Miranda
If I raise one Swagger at endpoint, it increases a Swagger in the browser. That is,
swagger/swagger.jon
in endpoint, in the browser I haveswagger/swagger/swagger.json
– Henrique
take a look at the visual studio in the output window which Exception it is launching, it may be something related in the controllers and not in the configuration
– Rafael Scheffer