Fix hot reload for Swagger documentation #230
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #224 - Fix Swagger documentation hot reload.
Issue details:
Hi @Burgyn , it seems that we still have an issue here. The hot reload is working now, the ocelot.json is reloaded and all the endpoints are accessible trough the Ocelot gateway. But the swagger documentation for all "hot reloaded" endpoints is not accessible. We can see it in the endpoint list in swagger but after selecting it the page is not loading and we receive a 500 response.
PS. If we restart the Ocelot service, swagger is accessible for hot reloaded endpoints.
Do you have any ideas? Thank you!
Later edit:
We observed that SwaggerEndpointRepository contains _swaggerEndPoints and _swaggerEndpointsOptions. It seems that _swaggerEndPoints it's not updated and contains 12 endpoints (old value before hot reload) and swaggerEndpointsOptions contains the correct number of endpoints after hot reload (13).
image
Info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/2 GET https://localhost:33555/swagger/docs/v4.0/batches - -
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HMHNT5C1AJVQ", Request id "0HMHNT5C1AJVQ:0000000B": An unhandled exception was thrown by the application.
System.Collections.Generic.KeyNotFoundException: The given key '/batches' was not present in the dictionary.
at System.Collections.Generic.Dictionary2.get_Item(TKey key) at MMLib.SwaggerForOcelot.Repositories.SwaggerEndPointProvider.GetByKey(String key) at MMLib.SwaggerForOcelot.Middleware.SwaggerForOcelotMiddleware.GetEndPoint(String path, ISwaggerEndPointProvider swaggerEndPointRepository) at MMLib.SwaggerForOcelot.Middleware.SwaggerForOcelotMiddleware.Invoke(HttpContext context, ISwaggerEndPointProvider swaggerEndPointRepository, IDownstreamSwaggerDocsRepository downstreamSwaggerDocs) at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]