feat(storage-service): Integrate Swagger for API documentation and versioning

- Added Swagger support in `Program.cs` to enhance API documentation and enable annotations.
- Updated project file to generate XML documentation for Swagger and included the `Swashbuckle.AspNetCore.Annotations` package.
- Modified `FilesController` and `QuotaController` to support API versioning and updated route attributes accordingly.
This commit is contained in:
Ho Ngoc Hai
2026-01-13 10:07:26 +07:00
parent d7852cde79
commit c7ca541c5f
4 changed files with 17 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ using StorageService.API.Application.Commands;
using StorageService.API.Application.Queries;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
using Asp.Versioning;
namespace StorageService.API.Controllers;
@@ -13,7 +14,8 @@ namespace StorageService.API.Controllers;
/// VI: Controller cho các thao tác file.
/// </summary>
[ApiController]
[Route("api/v1/files")]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/files")]
[SwaggerTag("File Management - Upload, download, and manage files")]
public class FilesController : ControllerBase
{

View File

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using StorageService.API.Application.Queries;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
using Asp.Versioning;
namespace StorageService.API.Controllers;
@@ -12,7 +13,8 @@ namespace StorageService.API.Controllers;
/// VI: Controller cho các thao tác quota storage.
/// </summary>
[ApiController]
[Route("api/v1/quota")]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/quota")]
[SwaggerTag("Quota Management - View and manage storage quotas")]
public class QuotaController : ControllerBase
{

View File

@@ -1,9 +1,12 @@
using Asp.Versioning;
using Asp.Versioning.ApiExplorer;
using FluentValidation;
using Hellang.Middleware.ProblemDetails;
using StorageService.API.Application.Behaviors;
using StorageService.Infrastructure;
using Serilog;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.SwaggerGen;
// EN: Configure Serilog early / VI: Cấu hình Serilog sớm
Log.Logger = new LoggerConfiguration()
@@ -64,6 +67,7 @@ try
builder.Environment.IsDevelopment();
});
// EN: Add Swagger / VI: Thêm Swagger
// EN: Add Swagger / VI: Thêm Swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
@@ -74,6 +78,9 @@ try
Version = "v1",
Description = "StorageService microservice API / API microservice StorageService"
});
// EN: Enable annotations / VI: Bật annotations
options.EnableAnnotations();
});
// EN: Add health checks / VI: Thêm health checks

View File

@@ -4,7 +4,9 @@
<AssemblyName>StorageService.API</AssemblyName>
<RootNamespace>StorageService.API</RootNamespace>
<Description>Web API layer with CQRS pattern for Storage Service</Description>
<UserSecretsId>storageservice-api</UserSecretsId>
<!-- EN: Enable XML documentation for Swagger / VI: Bật XML documentation cho Swagger -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
@@ -21,6 +23,7 @@
<!-- EN: Swagger/OpenAPI / VI: Swagger/OpenAPI -->
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.2.0" />
<!-- EN: API Versioning / VI: API Versioning -->
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.0" />
@@ -37,7 +40,6 @@
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="10.1.0" />
</ItemGroup>
<ItemGroup>