DependencyInjection.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Web.Api.Common;
  2. using Microsoft.OpenApi;
  3. using SharedKernel;
  4. namespace Web.Api;
  5. public static class DependencyInjection
  6. {
  7. public static IServiceCollection AddPresentation(this IServiceCollection services, AppSettings settings)
  8. {
  9. services.AddExceptionHandler<GlobalExceptionHandler>();
  10. services.AddProblemDetails();
  11. services.AddEndpointsApiExplorer();
  12. services.AddSwaggerGen(options =>
  13. {
  14. // Nested type (예: GoogleLogin.Request, ForgotPassword.Request 등)
  15. // 이 short name `Request` 로 schemaId 충돌 → FullName 으로 unique 보장 (`+` 를 `.` 로 치환해 가독성).
  16. options.CustomSchemaIds(t => t.FullName?.Replace('+', '.') ?? t.Name);
  17. // internal: 기존 /api/* (대시보드 전용)
  18. options.SwaggerDoc("internal", new OpenApiInfo
  19. {
  20. Title = "ANTOOZA Internal API",
  21. Version = "v1",
  22. Description = "사용자/관리자 페이지 전용. 외부 노출 안 됨."
  23. });
  24. options.DocInclusionPredicate((docName, apiDesc) =>
  25. {
  26. var groupName = apiDesc.GroupName ?? "internal";
  27. return docName == groupName;
  28. });
  29. options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
  30. {
  31. Type = SecuritySchemeType.Http,
  32. Scheme = "bearer",
  33. BearerFormat = "JWT",
  34. Description = "JWT access_token 을 입력하세요."
  35. });
  36. options.AddSecurityRequirement(document => new() { [new OpenApiSecuritySchemeReference("Bearer", document)] = [] });
  37. // OpenAPI 3.x servers field — Scalar / Swagger UI 의 server selector + "Try it out" base URL.
  38. // 환경별 (운영=api.antooza.com / LOCAL=localhost:4000) 로 자동 채워짐 (App:ApiURL 기반).
  39. options.AddServer(new OpenApiServer
  40. {
  41. Url = settings.App.ApiURL,
  42. Description = $"{settings.App.Name} ({settings.App.ApiURL})"
  43. });
  44. });
  45. return services;
  46. }
  47. }