Custom Swagger API
Example of a Custom API with Authorization and Swagger
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using Umbraco.Cms.Api.Management.OpenApi;
using Umbraco.Cms.Core.Composing;
namespace Umbraco.Cms.Web.UI.New.Custom;
//Necessary code for the new API to show in the Swagger documentation and Swagger UI
public class MyBackOfficeSecurityRequirementsOperationFilter : BackOfficeSecurityRequirementsOperationFilterBase
{
protected override string ApiName => "my-api-v1";
}
public class MyConfigureSwaggerGenOptions : IConfigureOptions<SwaggerGenOptions>
{
public void Configure(SwaggerGenOptions options)
{
options.SwaggerDoc("my-api-v1", new OpenApiInfo { Title = "My API v1", Version = "1.0" });
options.OperationFilter<MyBackOfficeSecurityRequirementsOperationFilter>();
}
}
public class MyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
=> builder.Services.ConfigureOptions<MyConfigureSwaggerGenOptions>();
}


Last updated
Was this helpful?