Swagger API - 未提供 API 定义

问题描述 投票:0回答:1

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddControllersWithViews();

builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "API Name", Version = "v1" });
});
builder.Services.AddEndpointsApiExplorer();

var app = builder.Build();
app.UseForwardedHeaders();

if (app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}
app.UseSwaggerUi3();
app.UseSwaggerUI();
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "API Name V1");
});
app.UseRouting();
app.UseAuthentication();
app.MapControllers();

app.Run();

, 这是我的 .Net Core MVC 结构的 Program.cs 类。我有一些用于测试的 API,但我无法在 Swagger 上访问它们。

[Route("api/[controller]")]
    [ApiController]
    public class ApplicationAPIController : ControllerBase
    {
        readonly IApplicationService applicationService;
        readonly IMapper mapper;

        public ApplicationAPIController(IApplicationService applicationService, IMapper mapper)
        {
            this.applicationService = applicationService;
            this.mapper = mapper;
        }
        [HttpGet("GetList")]
        public IActionResult GetList()
        {
            var result = applicationService.GetList();
            if (result.Success)
            {
                return Ok(mapper.Map<List<Application>>(result.Data));
            }
            return BadRequest(result.Message);
        }

这是我的应用程序 API 类,但我无法访问 Swagger,我不知道我哪里做错了

c# asp.net-mvc swagger swashbuckle
1个回答
0
投票

我相信其中之一是问题的根源。

app.UseSwaggerUi3();
app.UseSwaggerUI();
© www.soinside.com 2019 - 2024. All rights reserved.