Swagger .NETCORE can't read json
See original GitHub issueI’m having a trouble with swagger in .netcore. I’ve tried everything and nothing. I saw another similar questions, but nothing works for me. Running my webapi app with swagger, always returns “Can’t read swagger JSON from http://localhost:5000/api/swagger/v1/swagger.json”.
My codes:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()));
services.AddMvc();
services.AddSwaggerGen();
services.ConfigureSwaggerGen(options =>
{
var info = new Info
{
Version = "v1",
Title = "Web API Multiprodutos",
Description = "Web API Multiprodutos",
Contact = new Contact { Name = "Marcos Monte", Url = "www.arrowbus.com.br" }
};
options.SingleApiVersion(info);
string caminhoAplicacao = AppContext.BaseDirectory;
string nomeAplicacao =
PlatformServices.Default.Application.ApplicationName;
string caminhoXmlDoc =
Path.Combine(caminhoAplicacao, $"{nomeAplicacao}.xml");
options.IncludeXmlComments(caminhoXmlDoc);
options.IgnoreObsoleteProperties();
options.IgnoreObsoleteActions();
options.DescribeAllEnumsAsStrings();
});
services.AddTransient<IServicoSimulacao, ServicoSimulacao>();
services.AddTransient<IAplicacaoLocalidade, AplicacaoEndereco>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
app.UseApplicationInsightsExceptionTelemetry();
app.UseCors(builder =>
{
builder.AllowAnyOrigin();
builder.AllowAnyMethod();
builder.AllowAnyHeader();
});
app.UseCors("AllowAll");
app.UseMvc();
app.UseMvcWithDefaultRoute();
app.UseSwagger((httpRequest, swaggerDoc) =>
{
swaggerDoc.Host = httpRequest.Host.Value;
});
app.UseSwaggerUi(swaggerUrl: Configuration["AppSettings:VirtualDirectory"] + "/swagger/v1/swagger.json", baseRoute: "swagger/ui");
}
Project.json
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Aplicacao.Multiprodutos": "1.0.0-*",
"Dominio.MultiProdutos": "1.0.0-*",
"Swashbuckle": "6.0.0-beta902",
"Swashbuckle.AspNetCore": "1.0.0",
"Swashbuckle.SwaggerGen": "6.0.0-beta902",
"Swashbuckle.SwaggerUi": "6.0.0-beta902",
"Infra.Repositorio.MultiProdutos": "1.0.0-*"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"xmlDoc": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Please, help me.Thanks in advance.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Swagger .NETCORE can't read json
Running my webapi app with swagger, always returns "Can't read swagger JSON from http://localhost:5000/api/swagger/v1/swagger.json". My codes:
Read more >Can't read swagger JSON in ASP.NET Core #128
Hi I have read many posts on this issue but none of them seem to relate to the ASP.NET Core implementation. Swashbuckle works...
Read more >ASP Core Web API - What is swagger.json file
Hi. Please help me to understand role of 'swagger.json' file. I cant find location of generated 'swagger.json' file on my disk.
Read more >Get started with Swashbuckle and ASP.NET Core
Swagger : a Swagger object model and middleware to expose SwaggerDocument objects as JSON endpoints. Swashbuckle.AspNetCore.
Read more >Swashbuckle.WebApi
NET Core, I've now shifted my focus to the Core-specific project - Swashbuckle.AspNetCore. ... Swagger-ui showing "Can't read swagger JSON from .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try this
app.UseSwagger(c => { c.RouteTemplate = "api/swagger/{documentName}/swagger.json"; }); app.UseSwaggerUI(c => { c.SwaggerEndpoint("v1/swagger.json", "Some API"); c.RoutePrefix = "api/swagger"; });
This should work.
For anyone experiencing this issue, please ensure you have the latest version of Swashbuckle.AspNetCore - v2.5.0 at the time of writing. If you’ve pulled that down and still experience this issue, let me know and I’ll re-open the ticket.