using Umbraco.Cms.Api.Common.OpenApi;
using Umbraco.Cms.Web.Common.ApplicationBuilder;
namespace Umbraco12Demo
{
public class MySwaggerRouteTemplatePipelineFilter : SwaggerRouteTemplatePipelineFilter
{
public MySwaggerRouteTemplatePipelineFilter(string name) : base(name)
{
}
/// <summary>
/// This is how you change the route template for the Swagger docs.
/// </summary>
protected override string SwaggerRouteTemplate(IApplicationBuilder applicationBuilder) => "swagger/{documentName}/swagger.json";
/// <summary>
/// This is how you change the route for the Swagger UI.
/// </summary>
protected override string SwaggerUiRoutePrefix(IApplicationBuilder applicationBuilder) => "swagger";
/// <summary>
/// This is how you configure Swagger to be available always.
/// Please note that this is NOT recommended.
/// </summary>
protected override bool SwaggerIsEnabled(IApplicationBuilder applicationBuilder) => true;
}
public static class MyConfigureSwaggerRouteUmbracoBuilderExtensions
{
// call this from ConfigureServices() in Startup, i.e.:
// services.AddUmbraco(_env, _config)
// ...
// .ConfigureMySwaggerRoute()
// .Build();
public static IUmbracoBuilder ConfigureMySwaggerRoute(this IUmbracoBuilder builder)
{
builder.Services.Configure<UmbracoPipelineOptions>(options =>
{
//include this line if you do NOT want the Swagger docs at / umbraco / swagger
//options.PipelineFilters.RemoveAll(filter => filter is SwaggerRouteTemplatePipelineFilter);
//setup your own Swagger routes
options.AddFilter(new MySwaggerRouteTemplatePipelineFilter("MyApi"));
});
return builder;
}
}
}
yes I had the same problem, but the code worked on my project
public class SwaggerRouteProductionPipelineFilter() : SwaggerRouteTemplatePipelineFilter("umbraco")
{
/// <summary>
/// This is how you configure Swagger to be available always.
/// Please note that this is NOT recommended.
/// </summary>
protected override bool SwaggerIsEnabled(IApplicationBuilder applicationBuilder) => true;
}
public static class MyConfigureSwaggerRouteUmbracoBuilderExtensions
{
public static IUmbracoBuilder ConfigureProductionSwaggerRoute(this IUmbracoBuilder builder)
{
builder.Services.Configure<UmbracoPipelineOptions>(options =>
{
options.PipelineFilters.RemoveAll(filter => filter is SwaggerRouteTemplatePipelineFilter);
options.AddFilter(new SwaggerRouteProductionPipelineFilter());
});
return builder;
}
}
then in program.cs I've updated it like this:
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
//here is the initializer
.ConfigureProductionSwaggerRoute()
.Build();
Content Delivery API: Can Not Access Swagger In Production Mode
Hi everyone,
I'm playing around with Content Delivery API. As i know, Swagger is disabled when the site is in production mode by default.
I followed the official document below to make it available always but it didn't work.
https://docs.umbraco.com/umbraco-cms/reference/api-versioning-and-openapi#swagger-route-and-or-availability
Do I need to do anything else?
My code was below:
In MySwaggerRouteTemplatePipelineFilter.cs
In Startup.cs
Thanks!
yes I had the same problem, but the code worked on my project
then in program.cs I've updated it like this:
is working on a reply...