Burgyn / MMLib.SwaggerForOcelot

This repo contains swagger extension for ocelot.
MIT License
351 stars 93 forks source link

Allow InjectJavascript and InjectStylesheet on the UseSwaggerForOcelotUI method #299

Closed pvanhooren closed 2 months ago

pvanhooren commented 3 months ago

Discussed in https://github.com/Burgyn/MMLib.SwaggerForOcelot/discussions/298

Originally posted by **pvanhooren** June 12, 2024 I am currently in the process of writing a second API application in our microservices codebase and I stumbled upon this package when researching how to combine two Swagger documentation pages. I have set everything up to create the combined Swagger page with version selector and all, but now I can't find the option to inject my own stylesheet and JavaScript file to customize the documentation. Our current Swagger page does have custom CSS and JavaScript, so I'd rather have it on our new combined one as well. Now I cannot find the extension method in UseSwaggerForOcelotUI , which I assumed to be the substitution of UseSwaggerUI, which does support these extension methods. Therefore I assume this feature is not (yet) supported. I'd also love to hear if that's wrong and if there's a workaround. But if not, I'd like to suggest the idea of adding this here as it would be very helpful for my case and probably many others :) Here's what I expect to be able to do: ``` app.UseSwaggerForOcelotUI(opt => { opt.InjectStylesheet("/swagger-ui/swagger.min.css"); opt.InjectJavascript("/swagger-ui/swagger.js"); }).UseOcelot().Wait(); ``` or something along those lines. Again, I'm open for workarounds too, please join the discussion if you have anything to say on this topic!
Burgyn commented 2 months ago

Hi @pvanhooren,

try to use overload method with setupAction. Something like:

app.UseSwaggerForOcelotUI(opt =>
{
    // configure OcelotSwaggerUIOptions
}, setup =>
{
    // configure SwaggerUIOptions
    // 👇 this is place for you
    setup.InjectJavascript("/swagger-ui/custom.js");
    setup.InjectStylesheet("/swagger-ui/custom.css");
}).UseOcelot().Wait();