OrchardCoreContrib.Modules icon indicating copy to clipboard operation
OrchardCoreContrib.Modules copied to clipboard

How to hide `QueryApi` in OrchardCoreContrib.Apis.Swagger, and also hide the Swagger in a Release environment?

Open MarGraz opened this issue 1 year ago • 4 comments

Hi Everyone,

I installed the OrchardCoreContrib.Apis.Swagger version 1.5.0. In my Orchard Core 2.0.1 I have enabled the features Queries and SQL Queries, and I saw in the Swagger UI a QueryApi section with two endpoints exposed.

  1. Is there a way to turn off those Queries API? Or they are used by OC?
  2. Is it possible to remove them from the Swagger, without turning off the Queries feature?
  3. Is it possible to avoid showing the Swagger in a Release environment?

Thank you

MarGraz avatar Dec 05 '24 15:12 MarGraz

@hishamco I forgot to mention you, do you have any idea about this? At least to hide the Swagger in a Release env. Thank you

MarGraz avatar Dec 05 '24 17:12 MarGraz

Is it possible to avoid showing the Swagger in a Release environment?

This could be doable by making use of a hosting environment, but I'm not sure why you need to disable the swagger page in the production

For the first two questions I need to check if there's a way

hishamco avatar Dec 05 '24 23:12 hishamco

@hishamco thank you for your reply.

What do you mean by "making use of a hosting environment"? Is it possible from the Program.cs use the IsDevelopment? I tried it this way, but it doesn't seem to work:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOrchardCms()
 .ConfigureServices(services =>
 {
     // Here Orchard Core parts and handlers
 })
.Configure(app =>
{
    // Configure the Swagger only for Dev Env
    if (app.ApplicationServices.GetRequiredService<IHostEnvironment>().IsDevelopment())
    {
        app.UseSwagger(c =>
        {
            // Configure Swagger path
            c.RouteTemplate = "{tenant}/swagger/{documentName}/swagger.json";
        });

        app.UseSwaggerUI(c =>
        {
            // Configure Swagger UI path
            c.SwaggerEndpoint("v1.0.0/swagger.json", "Librostore Payments API v1.0.0");
            c.RoutePrefix = "swagger"; // Swagger UI is accessible on {tenant}/swagger/index.html
        });
    }
});

var app = builder.Build();

[...]

The reason why I need to disable the swagger page, is because my API are used only by other microservices, and I don't need to provide the swagger to the final user.

Maybe I can create a project swagger module in my solution, copying the OrchardCoreContrib.Apis.Swagger, and use IsDevelopment in the module Startup 🤔

Thank you

MarGraz avatar Dec 06 '24 09:12 MarGraz

Maybe I can create a project swagger module in my solution, copying the OrchardCoreContrib.Apis.Swagger, and use IsDevelopment in the module Startup 🤔

Why not disable feature in production site

hishamco avatar Mar 22 '25 03:03 hishamco