feat: Update Swagger configuration and launch settings for Membership Service API

- Downgraded Swashbuckle.AspNetCore.Annotations package to version 7.2.0 for compatibility.
- Enhanced Swagger documentation with detailed API description, features, and contact information.
- Added JWT Bearer security definition to improve API security.
- Updated launch settings to change the application URL from localhost:5000 to localhost:5003.
This commit is contained in:
Ho Ngoc Hai
2026-01-15 16:49:44 +07:00
parent f17578594f
commit 0a3db83704
3 changed files with 58 additions and 4 deletions

View File

@@ -36,7 +36,7 @@
<!-- EN: JWT Bearer authentication / VI: JWT Bearer authentication -->
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="10.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.2.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -3,6 +3,7 @@ using FluentValidation;
using Hellang.Middleware.ProblemDetails;
using MembershipService.API.Application.Behaviors;
using MembershipService.Infrastructure;
using Microsoft.OpenApi.Models;
using Serilog;
// EN: Configure Serilog early / VI: Cấu hình Serilog sớm
@@ -68,12 +69,65 @@ try
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new()
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Membership Service API",
Version = "v1",
Description = "Membership Service API - Manage member profiles and membership levels"
Description = """
Membership Service API - Manage member profiles and membership levels
## Features
- Member profile management
- Membership levels (Free/Basic/Premium)
- User preferences
""",
Contact = new OpenApiContact
{
Name = "GoodGo Team",
Email = "support@goodgo.com",
Url = new Uri("https://github.com/goodgo")
},
License = new OpenApiLicense
{
Name = "MIT License",
Url = new Uri("https://opensource.org/licenses/MIT")
}
});
// EN: Include XML comments for better documentation
// VI: Include XML comments để documentation tốt hơn
var xmlFilename = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFilename);
if (File.Exists(xmlPath))
{
options.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
}
// EN: Add JWT Bearer security definition / VI: Thêm JWT Bearer security definition
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.Http,
Scheme = "bearer",
BearerFormat = "JWT",
Description = "JWT Authorization header using the Bearer scheme. Example: 'Bearer {token}'"
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
Array.Empty<string>()
}
});
// EN: Enable annotations / VI: Bật annotations
options.EnableAnnotations();
});

View File

@@ -6,7 +6,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"applicationUrl": "http://localhost:5003",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}