Swagger with ocelot response status 500

22 Views Asked by At

I'm creating web app for car administrations and reservations. I'm using API Gateway with Ocelot. I've used SwaggerForOcelot, Ocelot and Swashbuckle nugets. Here are some examples of my code: API Gateway Startup.cs

public sealed class Startup
{ public IConfiguration Configuration { get; } public Startup(IConfiguration configuration) { Configuration = configuration; }`

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
        services.AddOcelot();
        services.AddSwaggerForOcelot(Configuration);
    }
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseRouting();
        app.UseEndpoints(endpoints => endpoints.MapControllers());
        app.UseSwaggerForOcelotUI();
        app.UseOcelot().Wait();
    }

}

ocelot.json

{     "$schema": "https://json.schemastore.org/ocelot.json",     "Routes": [         {             "DownstreamPathTemplate": "/carReservation/{everything}",             "DownstreamScheme": "https",             "DownstreamHostAndPorts": [                 {                     "Host": "localhost",                     "Port": 30001                 }             ],             "UpstreamPathTemplate": "/api/carReservation/{everything}",             "UpstreamHttpMethod": [ "Get" ],             "SwaggerKey": "carReservations"         },     ],     "SwaggerEndPoints": [         {             "Key": "carReservations",             "Config": {                 "Name": "Car Reservation API",                 "Version": "v1",                 "Url": "https://localhost:30001/swagger/v1/swagger.json"             }         }     ],     "GlobalConfiguration": {         "BaseUrl": "https://localhost:8081"     } }

CarReservation's service Startup.cs

public sealed class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
        services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApiInfo { Title =    "CarManager.CarReservation", Version = "v1" }));
    }
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseRouting();
        app.UseSwagger();
        app.UseSwaggerUI();
        app.UseEndpoints(endpoints => endpoints.MapControllers());
    }

}

CarReservation's controller

[ApiController]
[Route("[controller]/[action]")]
public class CarReservationController : ControllerBase
{
[HttpGet]
public IActionResult GetCarReservations()
{
return Ok("Car Reservations");
}

    [HttpPost]
    public IActionResult CreateCarReservation()
    {
        return Ok("Car Reservation Created");
    }

}

However, i'm getting this error. Any help what could be wrong?

https://i.stack.imgur.com/swiAg.png

I think I've tried everything what I could find.. The localhost:30001/swagger works as expected, however the API Gateway's swagger shows that error.

0

There are 0 best solutions below