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

Support multi-tenant use case for SwaggerGenOptions

Open markphillips100 opened this issue 6 years ago • 0 comments

Currently, a ISwaggerProvider instance is created using an internal method on the SwaggerGenOptions class, and an instance of this class is supplied from the DI container using IOptions<SwaggerGenOptions>. See the code here.

I have a multi-tenant API that makes use of a multi-tenant openid authority for authentication of the swagger client, so I need to provide different options per tenant URL path. I typically do this by using IOptionsMonitor<TOptions> rather than IOptions<TOptions>, and then I implement the monitor class to supply the dynamic, per-tenant data.

My problem here though is that I cannot simply write the following as the CreateSwaggerProvider method is internal to the SwaggerGen project.

        private static ISwaggerProvider CreateSwaggerProvider(IServiceProvider serviceProvider)
        {
            var swaggerGenOptions = serviceProvider.GetRequiredService<IOptionsMonitor<SwaggerGenOptions>>().Value;
            return swaggerGenOptions.CreateSwaggerProvider(serviceProvider);
        }

So, can I request a change please. Either use IOptionsMonitor rather than IOptions, or make the CreateSwaggerProvider method public or protected.

markphillips100 avatar Jun 04 '18 11:06 markphillips100