teociaps / SwaggerUI.Themes

Change theme to your Swagger API documentation in ASP.NET Core applications.
MIT License
14 stars 0 forks source link

Bug: Does not work when setting SwaggerUIOptions #14

Closed Scal-Human closed 3 months ago

Scal-Human commented 3 months ago

Guidelines

Project Version

0.5.0.0

.NET Version

net8.0

What happened?

Does nothing when defining SwaggerUIOptions along with the style

Steps to reproduce

app.UseSwaggerUI(Style.DeepSea, (SwaggerUIOptions options) => { options.DisplayOperationId(); });

Expected behavior

Changes the theme.

Additional Information

Works when removing the SwaggerUIOptions. app.UseSwaggerUI(Style.DeepSea);

teociaps commented 3 months ago

Hi @Scal-Human,

I tried to reproduce the issue you're experiencing, but it works for me using the following code: app.UseSwaggerUI(Style.DeepSea, (SwaggerUIOptions options) => { options.DisplayOperationId(); });

Do you see the loaded styles in your browser sources? Are there any errors printed in your browser console? Have you cleared your browser cache?

Scal-Human commented 3 months ago

Hello, Thank you for your concern. No, I do not see any error, neither on the console, nor is the browser. The style is simply ignored on both Windows and Linux (Docker container). FYI: using the options was a test I removed anyway. Thanks for your job, by the way ;-) Scal

teociaps commented 3 months ago

Oh, okay. I will investigate further. For now, I close this issue because I can't reproduce it, and it doesn't seem to be a bug. Thank you!

Scal-Human commented 3 months ago

Thank you Tarek. In the meantime, I had to change the order of the middlewares I am using in my tests (trying to find common ground for all future servers), and with those changes, I added back a SwaggerUIOptions to have a standard openapi.json name instead of swagger.json and it now works.

app.UseSwaggerUI(Style.Dark, (SwaggerUIOptions options) => {
    options.SwaggerEndpoint("v1/openapi.json", "Version 1");
    options.RoutePrefix = "api";
});

Unfortunately, I do not have anymore the exact code that was not working (but it was really simple). What I suggest is for you not to investigate for now, and will come back to you if I can reproduce the case that was not working.

Thank you for your time, Scal

oasaleh commented 1 month ago

@Scal-Human, here's the error. It's not being recognized.

image

Here's the code,

        app.UseSwagger();
        app.UseSwaggerUI(
            ModernStyle.Dark,
            c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "PodiumApi v1");
                c.RoutePrefix = string.Empty; // this changes the default path
                c.EnableTryItOutByDefault();
                c.DocExpansion(DocExpansion.None);
            });

This is the error when trying to build. Startup.cs(76,9): Error CS1929 : 'IApplicationBuilder' does not contain a definition for 'UseSwaggerUI' and the best extension method overload 'StyleSwaggerUIBuilderExtensions.UseSwaggerUI(WebApplication, BaseStyle, SwaggerUIOptions)' requires a receiver of type 'Microsoft.AspNetCore.Builder.WebApplication'

teociaps commented 1 month ago

Yeah, that error occurs because the methods extend WebApplication, not IApplicationBuilder.

I'll go ahead and update them to support that interface as well. Ty @oasaleh

Scal-Human commented 1 month ago

@oasaleh You found it, super. Many thanks

teociaps commented 1 month ago

@Scal-Human @oasaleh I'm back just to inform you I have added the IApplicationBuilder support (and other stuff) on version 1.0.0 (See the latest release)! Please upgrade your package to check it out. :D

Scal-Human commented 1 month ago

@teociaps Thank you, have a nice day.