Program.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Microsoft.AspNetCore.Mvc.Controllers;
  2. using Microsoft.OpenApi.Models;
  3. var builder = WebApplication.CreateBuilder(args);
  4. builder.Services.AddCors();
  5. builder.Services.AddControllers();
  6. builder.Services.AddSwaggerGen(option =>
  7. {
  8. option.SwaggerDoc("v1", new OpenApiInfo { Title = "", Version = "v1" });
  9. option.TagActionsBy(api =>
  10. {
  11. if (api.GroupName != null)
  12. {
  13. return new[] { api.GroupName };
  14. }
  15. var controllerActionDescriptor = api.ActionDescriptor as ControllerActionDescriptor;
  16. if (controllerActionDescriptor != null)
  17. {
  18. return new[] { controllerActionDescriptor.ControllerName };
  19. }
  20. throw new InvalidOperationException("Unable to determine tag for endpoint.");
  21. });
  22. option.DocInclusionPredicate((name, api) => true);
  23. });
  24. var app = builder.Build();
  25. app.MapControllerRoute(
  26. name: "default",
  27. pattern: "{controller =Home}/{action=Index}/{id?}");
  28. app.UseCors(builder => builder.AllowAnyOrigin());
  29. app.UseSwagger();
  30. app.UseSwaggerUI(options =>
  31. {
  32. options.SwaggerEndpoint("./v1/swagger.json", "v1");
  33. });
  34. app.Run();