Failed to load API definition.
See original GitHub issueHi,
I am not quite sure whether this issue has to do with Ocelot or Swagger configuration. But here goes.
On our project we have an Ocelot application (aspnet core 3.1) which, so far, has one downstream microservice and additional microservices coming over time. Now I am in the process of setting up SwaggerForOcelot, but something is killing me in the configuration part.
Describe the bug Our Ocelot application is running at localhost:44382/gateway/ and the microservice is running in the background. Swagger is not present at this root url. When trying to access localhost:44382/gateway/index.html I’m getting the error “Failed to load API definition”. At localhost:44382/gateway/swagger/v1/swagger.json I can reach the Swagger file of our microservice. But it seems that Swagger cannot find the file. Requests to the microservice through Ocelot are working perfect, so this must be a Swagger issue. Swagger is set up on the microservice and is working perfect too.
When removing “gateway/” part from the url in ocelot.json and launchSettings.json, Swagger is suddenly present at the root url localhost:44382/index.html. What am I missing here? Am I supposed to register the “gateway/” part somewhere else to get this working?
Expected behavior I would expect Swagger to appear at localhost:44382/gateway/index.html.
To Reproduce ocelot.json
{
"Routes": [
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44310
}
],
"UpstreamPathTemplate": "/gateway/{everything}",
"UpstreamHttpMethod": [ "GET" ],
"DangerousAcceptAnyServerCertificateValidator": false,
"RouteIsCaseSensitive": false,
"UpstreamHeaderTransform": {
"Secret": "************"
},
"SwaggerKey": "klientaktiviteter"
}
],
"SwaggerEndPoints": [
{
"Key": "klientaktiviteter",
"Config": [
{
"Name": "Klient Aktiviteter v1",
"Version": "v1",
"Url": "https://localhost:44310/swagger/v1/swagger.json"
}
]
}
]
}
Startup.cs ConfigureServices()
services.AddSwaggerForOcelot(Configuration);
Startup.cs Configure()
app.UseSwaggerForOcelotUI(opts =>
{
opts.PathToSwaggerGenerator = "/swagger/docs";
opts.RoutePrefix = string.Empty;
});
launchSettings.json
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "gateway/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
Thank you.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Hi @Burgyn, That doesn’t work either.
To understand how your library works, I have been looking at your demo. But as I mentioned in my previous comment, that doesn’t work for me either. When running the ContactService, OrderService and the ApiGateway together, I would expect to be able to view Swagger schemes for these services. I can choose the services and versions from the drop down menu. But the same “Failed to load API definition” error appears for all of them even though they’re running. Are you sure that a general bug could not be the reason for this?
I hope we can fix this somehow soon.
Thanks again 😃
Closing after 8 days of waiting for the additional info requested.