Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

Dynamically Changing the Swagger UI Endpoints at Runtime

Open kieronlanning opened this issue 5 years ago • 9 comments

Is there a way of re-populating the endpoints Swagger-UI uses at runtime?

Currently, when building the Swagger UI endpoints we would do something like this:

   // This is an example of what we currently do.
   app.UseSwaggerUI(setup => {
      // Get running services from k8s or config (when running locally).
      var services = serviceDiscovery.GetServices();
      foreach(var server in services) {
          app.SwaggerEndpoint(server.Name, $"http://{server.LocalDns}/swagger/swagger.json");
      }
   });

We'd like to be able to programmatically refresh that list based on service discovery inside of our k8s cluster.

As new services come up, old ones removed and existing ones updated we'd currently have to bounce the docs pod/ service that generates that list.

By refreshing it - on a timer, or via a web-hook from our build server - the changes would be automatically reflected.

kieronlanning avatar Mar 26 '19 11:03 kieronlanning