-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SwaggerEndPoints configuration section is missing or empty exception #90
Comments
@rajeshgithub001 I am happy to help! I have the code, I just havent made the time to build out the unit tests and thus havent submitted it as a PR. You have to replace the AddOcelot() with a custom extension that takes the SwaggerEndPoints into consideration. AddOcelot deserializes all of your individual files into a Model, which is why the SwaggerKey gets lost. I have an extension method replacement and a couple replacement classes to resolve the issue. It is working fine for me, and has been in production for a couple months now. |
@amadard Please provide an extension method ? |
First step is to replace the Ocelot FileReRoute, which is why the SwaggerKey is being dropped:
Then we need to replace the FileConfiguration to have the ReRoutes property use our new SwaggerFileReRoute model. This is a full redo, since we cant inherit and replace the ReRoutes property.
Then we are replacing the AddOcelot(this IConfigurationBuilder builder, string folder, IWebHostEnvironment env) method with our own version that properly uses the above models, and handles the SwaggerEndPoints. This is copy and update of the AddOcelot.
This requires your SwaggerEndPoints be in a file named "ocelot.SwaggerEndPoints.json". Then you call that extension method in replacement of AddOcelot()
|
Thanks a lot. |
hi guys, |
Sure thing! I will get it done this weekend. |
I am using SwaggerForOcelot with .net core 3.1 for api gateway.
Our ocelot json is divided into modules like below:-
ocelot.call-log.json
ocelot.column-chooser.json
ocelot.contact-list.json
ocelot.documentation.json
ocelot.global.json
ocelot.inventory-list.json
ocelot.json <= this is generated automatically.
ocelot.swagger.json <=define here swagger related configuration , pls find below
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "xx.xx.xx.xx",
"Port": 6004
}
],
"UpstreamPathTemplate": "{everything}",
"UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE" ],
"SwaggerKey": "all"
}
],
"SwaggerEndPoints": [
{
"Key": "all",
"Config": [
{
"Name": "Test API V1",
"Version": "v1",
"Url": "http://xx.xx.xx.xx:6004/swagger/v1/swagger.json"
}
]
}
]
}
On running it giving exception on below line:-
app.UseSwaggerForOcelotUI(Configuration, opt =>
{
opt.PathToSwaggerGenerator = "/swagger/docs";
});
Exception details:-
at Microsoft.AspNetCore.Builder.BuilderExtensions.GetConfiguration(IConfiguration configuration)
at Microsoft.AspNetCore.Builder.BuilderExtensions.<>c__DisplayClass1_0.b__0(SwaggerUIOptions c)
at Microsoft.AspNetCore.Builder.SwaggerUIBuilderExtensions.UseSwaggerUI(IApplicationBuilder app, Action
1 setupAction) at Microsoft.AspNetCore.Builder.BuilderExtensions.UseSwaggerForOcelotUI(IApplicationBuilder app, IConfiguration configuration, Action
1 setupAction)at SMARTS2.ApiGateway.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\rajesh.agrawal\source\repos\SMARTS 2.0 API\SMARTS2.0\SMARTS2.ApiGateway\Startup.cs:line 63
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
Let me know why this error coming ?
The text was updated successfully, but these errors were encountered: