SwaggerEndPoints configuration section is missing or empty exception
See original GitHub issueI 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.<UseSwaggerForOcelotUI>b__0(SwaggerUIOptions c)
at Microsoft.AspNetCore.Builder.SwaggerUIBuilderExtensions.UseSwaggerUI(IApplicationBuilder app, Action1 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.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
Let me know why this error coming ?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Sure thing! I will get it done this weekend.
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()