Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MarGraz opened this issue Dec 5, 2024 · 3 comments

Comments

@MarGraz
Copy link

MarGraz commented Dec 5, 2024

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 MarGraz changed the title How to hide QueryApi in OrchardCoreContrib.Apis.Swagger How to hide QueryApi in OrchardCoreContrib.Apis.Swagger, and also hide the Swagger in a Release environment? Dec 5, 2024
@MarGraz
Copy link
Author

MarGraz commented Dec 5, 2024

@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

@hishamco
Copy link
Member

hishamco commented Dec 5, 2024

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

@MarGraz
Copy link
Author

MarGraz commented Dec 6, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants