Burgyn / MMLib.SwaggerForOcelot

This repo contains swagger extension for ocelot.
MIT License
353 stars 94 forks source link

Error when used with Consul as service discovery provider #94

Closed Reintjuu closed 4 years ago

Reintjuu commented 4 years ago

With Consul up and running (available through port 8500), I'm not able to use this library to access an individual service's swagger documentation.

The Example service is configured as follows:

public void ConfigureServices(IServiceCollection services)
{
    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Example Service", Version = "v1" });
    });
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseSwagger();
}

And my ocelot.json:

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/{everything}",
      "ServiceName": "example",
      "UpstreamPathTemplate": "/api/example/{everything}",
      "SwaggerKey": "example"
    }
  ],
  "SwaggerEndPoints": [
    {
      "Key": "example",
      "Config": [
        {
          "Name": "Example",
          "Version": "v1",
          "Service": {
            "Name": "example",
            "Path": "/swagger/v1/swagger.json"
          }
        }
      ]
    }
  ],
  "GlobalConfiguration": {
    "ServiceDiscoveryProvider": {
      "Host": "consul",
      "Port": 8500,
      "Type": "Consul"
    }
  }
}

The services are accessible directly (by creating a simple API controller with a HttpGet method) but don't seem to be through swagger. I'm getting the following error in the logs:

System.InvalidOperationException: An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
   at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request)
   at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.GetStringAsync(String requestUri)
   at MMLib.SwaggerForOcelot.Middleware.SwaggerForOcelotMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Burgyn commented 4 years ago

Hi,

I never test this scenario. Because I have no experience with this service.

This library generally uses Service Discovery from Ocelot. It is possible that there is only a small problem, unfortunately I have no way to find it out (I do not have a ready environment). If you had any other information that could help me, that would be nice. For example, some adition info from a given exception. It would be ideal if you could connect this project directly to yours and debug what the problem is.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.

raga70 commented 7 months ago

I had the same issue and added support for Consul in my fork:https://github.com/raga70/MMLib.SwaggerForOcelot/tree/ConsulSupport

also made a pull request, so by the time you are reading this, it might already be in the main code base