Refactor: Rename DocumentOperator to DocumentService
Updated project and solution files to rename and restructure `DocumentOperator` to `DocumentService`. Modified project references in `DocumentService.API.csproj`, `DocumentService.Application.csproj`, and `DocumentService.Infrastructure.csproj` to reflect the new naming convention. Updated `DocumentService.sln` to remove old project references, add new ones, and adjust configuration and nested project mappings accordingly. This change aligns the project structure with the new naming convention.
This commit is contained in:
125
DocumentService.API/Configuration/DualInputDocumentFilter.cs
Normal file
125
DocumentService.API/Configuration/DualInputDocumentFilter.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace DocumentService.API.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Swagger document filter that merges operations with same path but different [Consumes] attributes.
|
||||
/// Ensures both multipart/form-data and application/json variants are visible in Swagger UI.
|
||||
/// </summary>
|
||||
public class DualInputDocumentFilter : IDocumentFilter
|
||||
{
|
||||
private readonly IApiDescriptionGroupCollectionProvider _apiDescriptionProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DualInputDocumentFilter"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiDescriptionProvider">API description provider to access all endpoints</param>
|
||||
public DualInputDocumentFilter(IApiDescriptionGroupCollectionProvider apiDescriptionProvider)
|
||||
{
|
||||
_apiDescriptionProvider = apiDescriptionProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the filter to merge operations with different content types.
|
||||
/// </summary>
|
||||
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
|
||||
{
|
||||
var allApiDescriptions = _apiDescriptionProvider.ApiDescriptionGroups.Items
|
||||
.SelectMany(g => g.Items)
|
||||
.ToList();
|
||||
|
||||
// Group by path
|
||||
var groupedByPath = allApiDescriptions
|
||||
.GroupBy(x => "/" + x.RelativePath)
|
||||
.ToList();
|
||||
|
||||
foreach (var group in groupedByPath)
|
||||
{
|
||||
var path = group.Key;
|
||||
|
||||
if (!swaggerDoc.Paths.ContainsKey(path))
|
||||
continue;
|
||||
|
||||
var pathItem = swaggerDoc.Paths[path];
|
||||
|
||||
// Find multipart and JSON variants
|
||||
var multipartDesc = group.FirstOrDefault(x =>
|
||||
x.SupportedRequestFormats.Any(f => f.MediaType == "multipart/form-data"));
|
||||
|
||||
var jsonDesc = group.FirstOrDefault(x =>
|
||||
x.SupportedRequestFormats.Any(f => f.MediaType == "application/json"));
|
||||
|
||||
// If we have both variants, merge them into single operation
|
||||
if (multipartDesc != null && jsonDesc != null)
|
||||
{
|
||||
var httpMethod = multipartDesc.HttpMethod?.ToLowerInvariant();
|
||||
OperationType operationType;
|
||||
|
||||
if (!Enum.TryParse<OperationType>(httpMethod, true, out operationType))
|
||||
continue;
|
||||
|
||||
if (!pathItem.Operations.ContainsKey(operationType))
|
||||
continue;
|
||||
|
||||
var operation = pathItem.Operations[operationType];
|
||||
|
||||
// Ensure RequestBody exists
|
||||
if (operation.RequestBody == null)
|
||||
{
|
||||
operation.RequestBody = new OpenApiRequestBody
|
||||
{
|
||||
Required = true,
|
||||
Content = new Dictionary<string, OpenApiMediaType>()
|
||||
};
|
||||
}
|
||||
|
||||
// Add multipart/form-data if missing
|
||||
if (!operation.RequestBody.Content.ContainsKey("multipart/form-data"))
|
||||
{
|
||||
operation.RequestBody.Content.Add("multipart/form-data", new OpenApiMediaType
|
||||
{
|
||||
Schema = new OpenApiSchema
|
||||
{
|
||||
Type = "object",
|
||||
Properties = new Dictionary<string, OpenApiSchema>
|
||||
{
|
||||
["file"] = new OpenApiSchema
|
||||
{
|
||||
Type = "string",
|
||||
Format = "binary",
|
||||
Description = "PDF file to upload"
|
||||
}
|
||||
},
|
||||
Required = new HashSet<string> { "file" }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add application/json if missing
|
||||
if (!operation.RequestBody.Content.ContainsKey("application/json"))
|
||||
{
|
||||
operation.RequestBody.Content.Add("application/json", new OpenApiMediaType
|
||||
{
|
||||
Schema = new OpenApiSchema
|
||||
{
|
||||
Type = "object",
|
||||
Properties = new Dictionary<string, OpenApiSchema>
|
||||
{
|
||||
["base64Pdf"] = new OpenApiSchema
|
||||
{
|
||||
Type = "string",
|
||||
Format = "byte",
|
||||
Description = "Base64-encoded PDF file content"
|
||||
}
|
||||
},
|
||||
Required = new HashSet<string> { "base64Pdf" }
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace DocumentService.API.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Placeholder class for Serilog configuration extensions.
|
||||
/// </summary>
|
||||
public class SerilogConfiguration
|
||||
{
|
||||
}
|
||||
}
|
||||
50
DocumentService.API/Configuration/SwaggerConfiguration.cs
Normal file
50
DocumentService.API/Configuration/SwaggerConfiguration.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DocumentService.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>
|
||||
/// <param name="configuration">Configuration to read SwaggerSettings from.</param>
|
||||
/// <returns>The modified service collection.</returns>
|
||||
public static IServiceCollection AddSwaggerDocumentation(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
var swaggerSettings = configuration.GetSection(SwaggerSettings.SectionName).Get<SwaggerSettings>()
|
||||
?? new SwaggerSettings();
|
||||
|
||||
services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc(swaggerSettings.Version, new OpenApiInfo
|
||||
{
|
||||
Title = swaggerSettings.Title,
|
||||
Version = swaggerSettings.Version,
|
||||
Description = swaggerSettings.Description
|
||||
});
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
DocumentService.API/Configuration/SwaggerSettings.cs
Normal file
33
DocumentService.API/Configuration/SwaggerSettings.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
namespace DocumentService.API.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Configuration settings for Swagger/OpenAPI documentation.
|
||||
/// </summary>
|
||||
public class SwaggerSettings
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public const string SectionName = "SwaggerSettings";
|
||||
|
||||
/// <summary>
|
||||
/// Enable Swagger UI in Production environment.
|
||||
/// Default: true (allows production testing/debugging).
|
||||
/// </summary>
|
||||
public bool EnableInProduction { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// API title displayed in Swagger UI.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = "DocumentService API";
|
||||
|
||||
/// <summary>
|
||||
/// API version.
|
||||
/// </summary>
|
||||
public string Version { get; set; } = "v1";
|
||||
|
||||
/// <summary>
|
||||
/// API description displayed in Swagger UI.
|
||||
/// </summary>
|
||||
public string Description { get; set; } = "PDF document processing service";
|
||||
}
|
||||
Reference in New Issue
Block a user