vitalybibikov / AzureExtensions.Swashbuckle

This extension enriches Azure Functions with Swagger/ Open API support
https://www.linkedin.com/in/vitali-bibikov/
MIT License
67 stars 54 forks source link

Swagger Ui Custom Css #106

Closed SaMirzaei closed 6 months ago

SaMirzaei commented 1 year ago

Is there a possibility to add a custom CSS to Ui?

Cliabhach commented 1 year ago

I don't think there's any good mechanism built into the tool, at least not yet.

It's a little bit of a nuisance, but here's a workaround that should work:

  1. load the entire Swagger UI html as a Stream with ISwashBuckleClient.GetSwaggerUi
  2. read that Stream into a string
  3. do string replacement to inject your custom CSS inline

It would look something like this:

    Stream ui = client.GetSwaggerUi("swagger.json");

    string theHtml = new StreamReader(ui).ReadToEnd();
    string extra = "<style>mycss</style>";
    // TODO: Inject 'extra' into 'theHtml'

    HttpResponseMessage response = new(HttpStatusCode.OK)
    {
        Content = new StringContent(theHtml, Encoding.UTF8, "text/html")
    };
vitalybibikov commented 6 months ago

Fixed