1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.OpenApi.Models;
- var builder = WebApplication.CreateBuilder(args);
- builder.Services.AddCors();//Äîáàâëÿåì ñåðâèñû CORS
- builder.Services.AddControllers();//Äîáàâëÿåì êîíòðîëëåðû
- builder.Services.AddSwaggerGen(option =>
- {
- option.SwaggerDoc("v1", new OpenApiInfo { Title = "", Version = "v1" });
- 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()); //Ïîäêëþ÷àåì CORS
- //Ðàçðåøåíèå èñïîëüçîâàíèÿ ÏÎ äëÿ îáñëóæèâàíèÿ ñîçäàííîãî äîêóìåíòà JSON è ïîëüçîâàòåëüñêîãî èíòåðôåéñà Swagger
- app.UseSwagger();
- app.UseSwaggerUI(options =>
- {
- options.SwaggerEndpoint("./v1/swagger.json", "v1"); //Îòíîñèòåëüíûé ïóòü äî ïîëüçîâàòåëüñêîãî èíòåðôåéñà
- });
- app.Run();
|