Ocelot Chinese Documentation - Not Supported

Ocelot does not support the following points...

  • Chunked encoding - Ocelot will always take the body size and return the Content-Length header. If this doesn't fit your scene, I can only say sorry!
  • Forward host header - The host header you send to Ocelot will not be forwarded to downstream services. Apparently this will break everything :(
  • Swagger - I've looked at building swagger.json from Ocelot's ocelot.json several times, but it doesn't seem to fit

I have Ocelot enough. If you want to use Swagger with Ocelot, then you have to generate your own swagger.json and do the following in Startup.cs or Program.cs. The following code example registers a middleware that loads your manually generated swagger.json and returns it to /swagger/v1/swagger.json. Then use Swashbuckle.AspNetCore to register the SwaggerUI middleware.

app.Map("/swagger/v1/swagger.json", b =>
{
    b.Run(async x => {
        var json = File.ReadAllText("swagger.json");
        await x.Response.WriteAsync(json);
    });
});
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Ocelot");
});

app.UseOcelot().Wait();

The main reason I think Swagger doesn't make sense is that we've manually written our definitions in ocelot.json. If we want people developing for Ocelot to be able to see the available routes, then either share the ocelot.json with them (this should be as easy as accessing the repository) or use the Ocelot admin API so they can query Ocelot's configuration.

In addition to this, many people also configure Ocelot to proxy all traffic e.g. /products/{everything} to the product service, which if you parse and convert it to a Swagger path doesn't describe what is actually available. In addition, Ocelot has no concept that downstream services can return models, and connecting to one of the above ports can return multiple models. Ocelot doesn't know which modules need to use POST or PUT, so it gets messy, and finally when swagger.json changes at runtime, the Swashbuckle package doesn't reload it. Ocelot's configuration can be changed at runtime, which can cause Swagger and Ocelot information to not match. Unless I roll my own Swagger implementation.

If anyone wants a simple test of the Ocelot API, I recommend Postman. Maybe even write something that maps ocelot.json to postman json spec. But I'm not going to do that.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325856947&siteId=291194637