How to handle non-root gateway?
See original GitHub issueI have a question regarding the handling of swagger generation when the Ocelot gateway endpoint is not on root. Using the following ocelot.json:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/v1/settings/{everything}",
"DownstreamScheme": "http",
"ServiceName": "backendpreferences",
"UpstreamPathTemplate": "/api/v1/settings/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
"AuthenticationOptions": {
"AuthenticationProviderKey": "Bearer",
"AllowedScopes": []
},
"SwaggerKey": "settings"
}
],
"SwaggerEndPoints": [
{
"Key": "settings",
"TransformByOcelotConfig": true,
"Config": [
{
"Name": "My Settings API",
"Version": "v1",
"Service": {
"Name": "backendpreferences",
"Path": "/swagger/v1/swagger.json"
}
}
]
}
],
"GlobalConfiguration": {
"BaseUrl": "https://myapi.com/mygateway",
"RequestIdKey": "OcRequestId",
"AdministrationPath": "/administration",
"UseServiceDiscovery": true,
"ServiceDiscoveryProvider": {
"Host": "consul",
"Port": 8500,
"Type": "Consul"
}
}
In code the SwaggerForOcelot setup is very basic:
app.UseSwaggerForOcelotUI(opt =>
{
opt.PathToSwaggerGenerator = "/swagger/docs";
});
Ocelot itself works fine with this setup.
However, whenever we open the swagger documentation at https://myapi.com/mygateway/swagger/index.html
the page starts loading but it tries to load the subdocuments at https://myapi.com/swagger/docs
rather than the expected https://myapi.com/mygateway/swagger/docs
. This causes the page to not load fully and show a fetch error.
Is there a way to set the base url which SwaggerForOcelot should use for the gateway (or how to make it use the Ocelot baseUrl)?
We’ve tried something like opt.DownstreamSwaggerEndPointBasePath = "../swagger/docs";
as suggested in issue #113, and while this solved the loading of documents, it doesn’t fix the urls in the generated document itself. Those still go for the root and therefore the calls fail with a 404:
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (1 by maintainers)
Top GitHub Comments
We had set the base path in ocelot.json. But adding it in code using
UsePathBase
seems to have solved the issue.@alex-tselikovsky None of the above worked for me.
Had to do something like: