Swagger 未加载 - 无法加载 API 定义:错误未定义消息

Swagger not loading - Failed to load API definition: error undefined message

因为我试图将一个 public 方法更改为私有。问题将消失。

但是当我在两个方法上定义 public 方法作为下面的控制器代码时,它会报错。

任何人 help/advice 如果可能的话将不胜感激

WEBLABController.cs

[Route("api/SearchLABResults")]
    [HttpPost]
    public async Task<IActionResult> SearchLABResults([FromBody] SP_GET_LABResult_Overview.input data)
    {
        IActionResult response = Unauthorized();
        ......
        return response;
    }

AuthenticationController.cs

[Route("api/GenerateToken")]
    [HttpPost]
    public async Task<IActionResult> GenerateToken([FromBody] AuthenticationModel.input data)
    {
        IActionResult response = Unauthorized();
        ......
        return response;
    }

如果您向下滚动 swagger 视图,您会看到您正在使用的每个模型都显示在那里。 Swagger 需要这些名称是唯一的。

SP_GET_LABResult_Overview.inputAuthenticationModel.input 都生成 input 模式并导致 InvalidOperationException。

尝试将其中一个输入 类 更改为其他内容或像这样即时更改其架构。

services.AddSwaggerGen(options =>
{
    options.CustomSchemaIds(type => type.ToString());
});