1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /*
- * https://habr.com/ru/articles/513514/
- */
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.OpenApi.Models;
- namespace APINet
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- var builder = WebApplication.CreateBuilder(args);
- builder.Services.AddCors();
- builder.Services.AddControllers();
- builder.Services.AddSwaggerGen(option =>
- {
- option.SwaggerDoc("1v", new OpenApiInfo { Title = "API", Version = "1v" });
- option.TagActionsBy(api =>
- {
- if (api.GroupName != null)
- {
- return new[] { api.GroupName };
- }
- var controllerActionDescriptor = api.ActionDescriptor as ControllerActionDescriptor;
- if (controllerActionDescriptor != null)
- {
- return new[] { controllerActionDescriptor.ControllerName };
- }
- throw new InvalidOperationException("Unable to determine tag for endpoint.");
- });
- option.DocInclusionPredicate((name, api) => true);
- });
- var app = builder.Build();
- app.MapControllerRoute(
- name: "default",
- pattern: "{controller = Home}/{action=Index}/{id?}");
- app.UseCors(builder => builder.AllowAnyOrigin());
- app.UseSwagger();
- app.UseSwaggerUI(c =>
- {
- c.SwaggerEndpoint("/swagger/1v/swagger.json", "1v");
- c.RoutePrefix = string.Empty;
- });
- app.Run();
- }
- }
- }
|