Burgyn / MMLib.SwaggerForOcelot

This repo contains swagger extension for ocelot.
MIT License
352 stars 94 forks source link

Refresh Swagger specification when making use of the hot-reload functionality of Ocelot #224

Closed catalingoran closed 2 years ago

catalingoran commented 2 years ago

When updates are made on Ocelot JSON file the swagger specification should be able to react to this change and reload the updated specification.

At this time our solution is to restart Ocelot every time a change occurs. *And it's not so funny :P Even annoying 🍡

Do you have an idea how we can get this to work?

Thanks, Catalin

Burgyn commented 2 years ago

Hi @catalingoran

this is fixed in the new version 4.9.0, which will be release in a few minutes.

catalingoran commented 2 years ago

Hi @Burgyn,

Thank you so much!

Cheers! 🥂

catalingoran commented 2 years ago

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]