Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Self Documentation/Gateway Documentation

See original GitHub issue


I’ve followed the instruction to try and enable Gateway documentation but I am having issues.

Note: It is otherwise working perfectly except these steps - also note that /administration api is working perfectly.

One step of the instructions is to add;


This however causes exception at Startup. Please see below stack. Removing the above line removes the exception.

[02:31:34 ERR] HTTP GET / responded 500 in 3.8379 ms
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.<>c__DisplayClass0_0.<AddSwaggerForOcelot>b__3(SwaggerGenOptions c)
   at Microsoft.Extensions.Options.ConfigureNamedOptions`1.Configure(String name, TOptions options)
   at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at Microsoft.Extensions.Options.OptionsManager`1.<>c__DisplayClass5_0.<Get>b__0()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.GetService(IServiceProvider sp, Type type, Type middleware)
   at lambda_method(Closure , Object , HttpContext , IServiceProvider )
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_1.<UseMiddleware>b__2(HttpContext context)
   at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext)
   at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext)
[02:31:34 ERR] An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.<>c__DisplayClass0_0.<AddSwaggerForOcelot>b__3(SwaggerGenOptions c)

Subsequently, everything seems to work perfectly except when I select “gateway” from the drop down.

Fetch error undefined /swagger/docs/gateway/gateway


ConfigureServices Method

            Action<IdentityServerAuthenticationOptions> opts = o => {
                o.Authority = config["ApiResourceBaseUrls:AuthServer"];
                o.RequireHttpsMetadata = false;
                o.SupportedTokens = SupportedTokens.Both;
                o.SaveToken = true;
                o.ApiSecret = config["self:Secret"];
                o.ApiName = config["self:Id"];
           services.AddOcelot(config).AddAdministration(config["GlobalConfiguration:AdministrationPath"], opts);
           services.AddSwaggerForOcelot(config,options =>
                    options.GenerateDocsForGatewayItSelf = true;
                    //options.GenerateDocsForAggregates = true;

Configure Method

            app.UseSwaggerForOcelotUI(opt =>
                opt.PathToSwaggerGenerator = "/swagger/docs";

Expected behavior No Exception at startup and also the gateway documentation works.

To Reproduce Attached Ocelots file routes.txt

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

thebadiconcommented, Feb 8, 2021

Hi @thebadicon,

this information helped me solve it. This problem was solved in version 4.0.1. You probably can’t migrate to .NET 5, so I fixed it in version 3.2.1 too.

Please @thebadicon, @aarondglover try version 3.2.1 and let me know if it helped you.

Thank you for helping me improve this project.

Hello, Burgyn

I’ve updated the package to 3.2.1 version and problem no longer persists.

Thank You for making it work in .net core 3.1.

Burgyncommented, Jan 29, 2021

Hi @aarondglover, thanks for reporting this issue.

Unfortunately I can’t reproduce it. I need your help. Please can you write which version of this package you use? If you use the Swashbuckle.AspNetCore package directly, its version as well.

Please also write me how you call AddSwaggerForOcelot method in ConfigureServices.

Ideal if you can isolate this issue into the demo app.

Thanks for your cooperation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documenting REST APIs
Learn how to provide documentation support for an API Gateway REST API. ... To help customers understand and use your API, you should...
Read more >
Document an API using the API Gateway console
In this section, we describe how to create and maintain documentation parts of an API using the API Gateway console. A prerequisite for...
Read more >
Host your API Gateway documentation in API Gateway
Host your OpenAPI documentation in a Lambda in API Gateway without any additional infrastructure.
Read more >
Self-hosted gateway overview
The self-hosted gateway is an optional, containerized version of the default managed gateway included in every API Management service.
Read more >
Sample repo for self hosted API Gateway documentation
API Gateway Self -Hosted Documentation. Sample repo to show an API Gateway hosting its own OpenAPI documentation in a Lambda.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found