Swagger映射Api失败,报错Fetch error Internal Server Error /swagger/****/swagger.json

当我们使用swagger接口生成接口文档的时候,经常会出现映射失败的错误,这里主要原因有两个,

一个是没有为继承了Controller接口方法(action)提供合适的action特性[HttpGet],[HttpPost],值得注意的是,如果存在不允许外部访问仅允许action方法自己调用的,如果也写在了继承Controller接口的类中时,务必要提供[NoAction]的action特性注解,当然最好是把这样的方法写在外面,通过依赖注入的方式或者直接写成静态方法的形式来调用。

 
 [AllowAnonymous]
 [HttpPost("api/router")]
 public Task CustomerPrintAll(CustomerPrintDto input)
{
//业务代码。。。
await CheckPrinter(input);
//业务代码。。。
}

//内部调用的方法
[NonAction]
public async Task<CustomerPrintConfigDto> CheckPrinter(CustomerPrintConfigDto input)
{
//业务代码
}

第二个就是可供将外部调用的action,给予了private导致访问权限不一致的情况。

猜你喜欢

转载自blog.csdn.net/weixin_43604220/article/details/130520148