1
0
mirror of https://github.com/bitwarden/server synced 2025-12-10 13:23:27 +00:00
Files
server/src/SharedWeb/Swagger/SwaggerGenOptionsExt.cs
Daniel García 866a572d26 Enable custom IDs for bindings (#6340)
* Enable custom IDs for bindings

* Remove description
2025-09-18 13:41:19 +02:00

35 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace Bit.SharedWeb.Swagger;
public static class SwaggerGenOptionsExt
{
public static void InitializeSwaggerFilters(
this SwaggerGenOptions config, IWebHostEnvironment environment)
{
config.SchemaFilter<EnumSchemaFilter>();
config.SchemaFilter<EncryptedStringSchemaFilter>();
config.OperationFilter<ActionNameOperationFilter>();
// Set the operation ID to the name of the controller followed by the name of the function.
// Note that the "Controller" suffix for the controllers, and the "Async" suffix for the actions
// are removed already, so we don't need to do that ourselves.
config.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["controller"]}_{e.ActionDescriptor.RouteValues["action"]}");
// Because we're setting custom operation IDs, we need to ensure that we don't accidentally
// introduce duplicate IDs, which is against the OpenAPI specification and could lead to issues.
config.DocumentFilter<CheckDuplicateOperationIdsDocumentFilter>();
// These two filters require debug symbols/git, so only add them in development mode
if (environment.IsDevelopment())
{
config.DocumentFilter<GitCommitDocumentFilter>();
config.OperationFilter<SourceFileLineOperationFilter>();
}
}
}