- ASP.NET Core 내장 Rate Limiting (FixedWindow, IP 기반 분당 100회) - 한도 초과 시 HTTP 429 + ApiResponse(에러코드 106) 반환 - Swashbuckle.AspNetCore 6.9.0 기반 Swagger UI 추가 - 도메인별 API 문서 그룹 (all, public, auth 등 10개) - JWT Bearer 인증 UI (Authorize 버튼) - X-Service-Code/X-API-KEY 커스텀 헤더 자동 표시 필터 - Microsoft.AspNetCore.OpenApi 제거 (Swashbuckle과 호환 충돌) Closes #30
72 lines
2.8 KiB
C#
72 lines
2.8 KiB
C#
using Microsoft.OpenApi.Models;
|
|
using SPMS.API.Filters;
|
|
|
|
namespace SPMS.API.Extensions;
|
|
|
|
public static class SwaggerExtensions
|
|
{
|
|
public static IServiceCollection AddSwaggerDocumentation(this IServiceCollection services)
|
|
{
|
|
services.AddEndpointsApiExplorer();
|
|
services.AddSwaggerGen(options =>
|
|
{
|
|
options.EnableAnnotations();
|
|
|
|
// API 문서 그룹
|
|
options.SwaggerDoc("all", new OpenApiInfo
|
|
{
|
|
Title = "SPMS API - 전체",
|
|
Version = "v1",
|
|
Description = "Stein Push Message Service API"
|
|
});
|
|
options.SwaggerDoc("public", new OpenApiInfo { Title = "공개 API", Version = "v1" });
|
|
options.SwaggerDoc("auth", new OpenApiInfo { Title = "인증 API", Version = "v1" });
|
|
options.SwaggerDoc("account", new OpenApiInfo { Title = "계정 API", Version = "v1" });
|
|
options.SwaggerDoc("service", new OpenApiInfo { Title = "서비스 API", Version = "v1" });
|
|
options.SwaggerDoc("device", new OpenApiInfo { Title = "디바이스 API", Version = "v1" });
|
|
options.SwaggerDoc("message", new OpenApiInfo { Title = "메시지 API", Version = "v1" });
|
|
options.SwaggerDoc("push", new OpenApiInfo { Title = "푸시 API", Version = "v1" });
|
|
options.SwaggerDoc("stats", new OpenApiInfo { Title = "통계 API", Version = "v1" });
|
|
options.SwaggerDoc("file", new OpenApiInfo { Title = "파일 API", Version = "v1" });
|
|
|
|
// 전체 문서에는 모든 API 포함, 나머지는 GroupName 기준 필터링
|
|
options.DocInclusionPredicate((docName, apiDesc) =>
|
|
{
|
|
if (docName == "all") return true;
|
|
return apiDesc.GroupName == docName;
|
|
});
|
|
|
|
// JWT Bearer 인증 UI
|
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
|
{
|
|
Description = "JWT Bearer Token을 입력하세요. 예: {token}",
|
|
Name = "Authorization",
|
|
In = ParameterLocation.Header,
|
|
Type = SecuritySchemeType.Http,
|
|
Scheme = "bearer",
|
|
BearerFormat = "JWT"
|
|
});
|
|
|
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
{
|
|
{
|
|
new OpenApiSecurityScheme
|
|
{
|
|
Reference = new OpenApiReference
|
|
{
|
|
Type = ReferenceType.SecurityScheme,
|
|
Id = "Bearer"
|
|
}
|
|
},
|
|
Array.Empty<string>()
|
|
}
|
|
});
|
|
|
|
// SPMS 커스텀 헤더 필터
|
|
options.OperationFilter<SpmsHeaderOperationFilter>();
|
|
});
|
|
|
|
return services;
|
|
}
|
|
}
|