Program.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Microsoft.OpenApi.Models;
  2. using MusicAPI.BaseModel;
  3. using Microsoft.AspNetCore.Mvc.Controllers;
  4. namespace MusicAPI
  5. {
  6. public class Program
  7. {
  8. public static void Main(string[] args)
  9. {
  10. var builder = WebApplication.CreateBuilder(args);
  11. builder.Services.AddCors();
  12. builder.Services.AddControllers();
  13. builder.Services.AddSwaggerGen(option =>
  14. {
  15. option.SwaggerDoc("v1", new OpenApiInfo { Title = "ÑóïåðÄóïåðÊðóòàÿ API äëÿ ìóçûêàëüêîãî ñåðâèñà", Version = "v1" });
  16. option.TagActionsBy(api =>
  17. {
  18. if (api.GroupName != null)
  19. {
  20. return new[] { api.GroupName };
  21. }
  22. var controllerActionDescriptor = api.ActionDescriptor as ControllerActionDescriptor;
  23. if (controllerActionDescriptor != null)
  24. {
  25. return new[] { controllerActionDescriptor.ControllerName };
  26. }
  27. throw new InvalidOperationException("Unable to determine tag for endpoint.");
  28. });
  29. option.DocInclusionPredicate((name, api) => true);
  30. });
  31. var app = builder.Build();
  32. app.MapControllerRoute(
  33. name: "default",
  34. pattern: "{controller =SongController}/{action=GetSongs}");
  35. app.UseCors(builder => builder.AllowAnyOrigin());
  36. app.UseSwagger();
  37. app.UseSwaggerUI(options =>
  38. {
  39. options.SwaggerEndpoint("./v1/swagger.json", "v1");
  40. });
  41. app.Run();
  42. }
  43. }
  44. }