Incorrect URL for microservice swagger
See original GitHub issueDescribe the bug Swagger launched from the gateway is looking for the microservice swagger json at the wrong path
Expected behavior Swagger should populate microservice json data
To Reproduce Gateway API: localhost:44393 Users Microservice: localhost:44340
I am able to access the Users microservice json file directly at: https://localhost:44340/swagger/v1/swagger.json
But from the gateway page I am getting the error: Fetch error: Internal Server Error /swagger/docs/v1/users
I’m unable to figure out why that path is being used rather than the one specified in SwaggerEndPoints:Config:Url
In the Gateway API ocelot.json file:
{
"ReRoutes": [
{
"UpstreamPathTemplate": "/users/{everything}",
"DownstreamPathTemplate": "/{everything}",
"SwaggerKey": "users",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44340
}
]
}
],
"SwaggerEndPoints": [
{
"Key": "users",
"Config": [
{
"Name": "Users API",
"Version": "v1",
"Url": "https://localhost:44340/swagger/v1/swagger.json"
}
]
}
],
"GlobalConfiguration": {
"BaseUrl": "https://localhost:44393"
},
"AuthenticationOptions": {
"authPersistSingleRequest": "True"
}
}
gateway startup file:
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
namespace endpointApi.gateway
{
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.AddOcelot();
services.AddSwaggerForOcelot(Configuration);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseAuthorization();
app.UseSwaggerForOcelotUI(Configuration, opt =>
{
opt.DownstreamSwaggerHeaders = new[]
{
new KeyValuePair<string, string>("Key", "Value"),
new KeyValuePair<string, string>("Key2", "Value2"),
};
})
.UseOcelot()
.Wait();
}
}
}
** Users microservice Startup**
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
namespace endpointApi.sites.users
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddMvc();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Users API", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSwagger()
.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Users API V1");
});
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Swagger incorrect API path - spring boot
I'm using swagger and swagger UI to document my APIs. This is in a spring boot microservice set up. I am consolidating all...
Read more >Swashbuckle generates incorrect Swagger API URL
The issue seems to be caused by the fact that server.example.net is an API gateway. This seems to prevent Swashbuckle from correctly inferring ......
Read more >Solving the “Too many Swaggers” problem in a Microservice ...
This way I don't have to provide multiple swagger endpoints for my entire system. Let's take a look at what we need to...
Read more >Microservices API Documentation with Swagger2
Swagger is the most popular tool for designing, building and documenting RESTful APIs. It has nice integration with Spring Boot.
Read more >Links
Links. Links are one of the new features of OpenAPI 3.0. Using links, you can describe how various values returned by one operation...
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 FreeTop 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
Top GitHub Comments
Hi @emrehorasan Issue #53 is fixed in version
1.10.2
This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.