Introduced the `DualInputDocumentFilter` class to merge Swagger operations with the same path but different `[Consumes]` attributes (`multipart/form-data` and `application/json`) into a single operation. This ensures both content types are visible in the Swagger UI. Updated `SwaggerConfiguration.cs` to: - Resolve conflicting actions by keeping the first variant. - Register the `DualInputDocumentFilter` to enable content type merging.
44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using Microsoft.OpenApi.Models;
|
|
using System.Reflection;
|
|
|
|
namespace DocumentOperator.API.Configuration
|
|
{
|
|
/// <summary>
|
|
/// Provides extension methods for configuring Swagger/OpenAPI documentation.
|
|
/// </summary>
|
|
public static class SwaggerConfiguration
|
|
{
|
|
/// <summary>
|
|
/// Adds Swagger documentation generation to the service collection.
|
|
/// </summary>
|
|
/// <param name="services">The service collection to add Swagger to.</param>
|
|
/// <returns>The modified service collection.</returns>
|
|
public static IServiceCollection AddSwaggerDocumentation(this IServiceCollection services)
|
|
{
|
|
services.AddSwaggerGen(options =>
|
|
{
|
|
options.SwaggerDoc("v1", new OpenApiInfo
|
|
{
|
|
Title = "DD Document Operator API",
|
|
Version = "v1",
|
|
Description = "PDF Verarbeitungs-Service für Validierung, Stempel, Zertifikate, Anhänge & Zusammenführung"
|
|
});
|
|
|
|
// Resolve conflicting actions: Keep first variant
|
|
// DualInputDocumentFilter will merge both variants into single operation
|
|
options.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
|
|
|
|
// Add document filter to merge operations with different content types
|
|
options.DocumentFilter<DualInputDocumentFilter>();
|
|
|
|
// XML-Kommentare einbinden
|
|
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
|
options.IncludeXmlComments(xmlPath);
|
|
});
|
|
|
|
return services;
|
|
}
|
|
}
|
|
}
|