How to hide `QueryApi` in OrchardCoreContrib.Apis.Swagger, and also hide the Swagger in a Release environment?
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.
- Is there a way to turn off those Queries API? Or they are used by OC?
- Is it possible to remove them from the Swagger, without turning off the Queries feature?
- Is it possible to avoid showing the Swagger in a Release environment?
Thank you
@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
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 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
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