question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to load API definition.

See original GitHub issue

Hi,

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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RonniePoulsencommented, Feb 8, 2021

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 😃

0reactions
github-actions[bot]commented, Feb 18, 2021

Closing after 8 days of waiting for the additional info requested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swashbuckle/Swagger + ASP.Net Core: "Failed to load API ...
As soon as I explicitly set e.g. [HttpGet] the error disappears. The problem with this is, I need this method to fire for...
Read more >
WebApi Core / Swagger: "failed to load API definition" error
I was working with some ASP.NET WebApi code and needed to test something using the Swagger UI. Usually, it's just a matter of...
Read more >
How To Solve Failed to load API definition Response ...
This error occurs when the API definition file fails to load due to an internal server error. In this article, we will discuss...
Read more >
Swagger Failed to load API definition In ASP.NET Core API
The solution is that you have to change the default route configuration at the controller level when you have created more than one...
Read more >
Failed to load Swagger API definition for a Newly ...
I just pushed a .NET Core 6.0 WebAPI to Azure AppService. When I access the location I receive the following error issued when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found