question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hide SwaggerUI GUI on production

See original GitHub issue

hey there, is there a simple way to disable displaying the SwaggerUI when application is pushed on production. So far i tried conditioning using a classic #if !DEBUG

  /// <summary>
  /// Swagger Configuration
  /// </summary>
  public class SwaggerConfig
  {
    /// <summary>
    /// Register
    /// </summary>
    public static void Register()
    {
      var thisAssembly = typeof(SwaggerConfig).Assembly;

#if !DEBUG
      GlobalConfiguration.Configuration
          .EnableSwagger(c =>
              {
                // By default, the service root url is inferred from the request used to access the docs.
                // However, there may be situations (e.g. proxy and load-balanced environments) where this does not
                // resolve correctly. You can workaround this by providing your own code to determine the root URL.
                //
                c.RootUrl(req => "/my.API");
                // If schemes are not explicitly provided in a Swagger 2.0 document, then the scheme used to access
                // the docs is taken as the default. If your API supports multiple schemes and you want to be explicit
                // about them, you can use the "Schemes" option as shown below.
                //
                c.Schemes(new[] { "https", "http" });

                // Use "SingleApiVersion" to describe a single version API. Swagger 2.0 includes an "Info" object to
                // hold additional metadata for an API. Version and title are required but you can also provide
                // additional fields by chaining methods off SingleApiVersion.
                //
                c.SingleApiVersion("v1", "my.API");

But it still trying to load a Swagger page at /my.API/swagger/ui/index and i am getting an error 404.

Any help is much appriciated and i guess i am not the only one having this kind of requirements ?

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kilroyFRcommented, Mar 4, 2021

the 404 issue was error code on my side. I could finally the trick above (using the #if DEBUG) to hide swagger and load a start page instead of the swagger page.

0reactions
heldersepucommented, Mar 4, 2021

glad you got it to work … but I think that your current implementation with the #if !DEBUG condition removing the EnableSwagger will more than just hide the UI, the swagger.json will not be generated

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Turn Off Swagger-ui in Production
To disable Swagger in production, let's toggle whether this configuration bean is injected. 3. Using Spring Profiles. In Spring, we can use the ......
Read more >
How do you turn off swagger-ui in production
Put your swagger configuration into separate configuration class and annotate it with @Profile annotation -> so that it will be scanned into ...
Read more >
Spring Boot disable Swagger-ui in Production
Spring Boot disable Swagger-ui in Production. To disable Swagger-ui for production profile, first we need to define a maven profile.
Read more >
Authentication for swagger UI in production in ASP.Net Core
A Short guide on how to Secure your Swagger UI in production by providing proper authentication. ... Remove the swagger part from env....
Read more >
How do I disable swashbuckle swagger UI in production ...
I using swashbuckle v 5.6.0 for api documentation and ui for test in asp.net web api2. I do ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found