You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an issue when using Ocelot's PollConsul service discovery provider with dynamic service registration from code. The ServiceHostAndPort retrieved from the PollConsul provider does not include the URI scheme, causing an exception when attempting to access the Swagger URI. The exception is due to the missing scheme, making the URI invalid.
Problem:
When retrieving the ServiceHostAndPort using PollConsul, the scheme is missing.
As a result, when trying to get the Swagger URI, an exception is thrown: "URI is not valid" because the scheme is empty.
Routes are not defined in the ocelot.json file, as I am dynamically getting them.
My ocelot.json configuration:
Fix:
To resolve the missing scheme issue, I modified the SwaggerServiceDiscoveryProvider class in the GetSwaggerUri(...) method (after line 109). I added the following code to ensure the scheme is set properly:
if (builder.Scheme.IsNullOrEmpty())
builder.Scheme = conf?.Scheme ?? "http";
With this change, the Swagger URI is now constructed correctly.
Additional Issue:
After fixing the URI issue, I encountered another problem where the Swagger content was empty. Upon debugging, I noticed that the _transformer.Transform method clears the content when the ServiceProviderType is not Consul. However, my type is PollConsul.
Second Fix:
I added a condition to also check for PollConsul, and it resolved the issue: if (SwaggerServiceDiscoveryProvider.ServiceProviderType != "Consul" && SwaggerServiceDiscoveryProvider.ServiceProviderType != "PollConsul") { // original logic }
Can I submit a PR?
I'd like to contribute this fix via a pull request as I need to deploy my project to the server soon
The text was updated successfully, but these errors were encountered:
I encountered an issue when using Ocelot's PollConsul service discovery provider with dynamic service registration from code. The ServiceHostAndPort retrieved from the PollConsul provider does not include the URI scheme, causing an exception when attempting to access the Swagger URI. The exception is due to the missing scheme, making the URI invalid.
Problem:
When retrieving the ServiceHostAndPort using PollConsul, the scheme is missing.
As a result, when trying to get the Swagger URI, an exception is thrown: "URI is not valid" because the scheme is empty.
Routes are not defined in the ocelot.json file, as I am dynamically getting them.
My ocelot.json configuration:
Fix:
To resolve the missing scheme issue, I modified the SwaggerServiceDiscoveryProvider class in the GetSwaggerUri(...) method (after line 109). I added the following code to ensure the scheme is set properly:
With this change, the Swagger URI is now constructed correctly.
Additional Issue:
After fixing the URI issue, I encountered another problem where the Swagger content was empty. Upon debugging, I noticed that the _transformer.Transform method clears the content when the ServiceProviderType is not Consul. However, my type is PollConsul.
Second Fix:
I added a condition to also check for PollConsul, and it resolved the issue:
if (SwaggerServiceDiscoveryProvider.ServiceProviderType != "Consul" && SwaggerServiceDiscoveryProvider.ServiceProviderType != "PollConsul") { // original logic }
Can I submit a PR?
I'd like to contribute this fix via a pull request as I need to deploy my project to the server soon
The text was updated successfully, but these errors were encountered: