SwaggerGeneratorException: Ambiguous HTTP method for action - DevExpress.AspNetCore.Reporting.QueryBuilder.QueryBuilderController.Invoke (DevExpress.AspNetCore.Reporting.v19.1). Actions require an explicit HttpMethod binding for Swagger/OpenAPI 3.0
VS2022 WEBAPI+DevExpress.AspNetCore.Reporting.v19.1包启动时出现的Swagger问题,原因是没有实现AspNetCore.Reporting.v19.1的Controller.如果只是MVC不需要实现或控制Controller,要用Swagger调试就必须处理。
解决方法有2种
1Program中不加载DEV的Controller
builder.Services.AddSwaggerGen(c =>
{
c.DocInclusionPredicate((docName, apiDesc) =>
{
if (!apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)) return false;
// Exclude all DevExpress reporting controllers
return !methodInfo.DeclaringType.AssemblyQualifiedName.StartsWith("DevExpress", StringComparison.OrdinalIgnoreCase);
});
});
2实现DEV的Controller
随便建立一个Controller 粘贴控制器实现
[ApiExplorerSettings(IgnoreApi = true)]
[Route("DXXRDV")]
public class CustomWebDocumentViewerController : WebDocumentViewerController
{
public CustomWebDocumentViewerController(IWebDocumentViewerMvcControllerService controllerService) : base(controllerService) { }
public override Task<IActionResult> Invoke()
{
return base.Invoke();
}
}
[ApiExplorerSettings(IgnoreApi = true)]
[Route("DXXQB")]
public class CustomQueryBuilderController : QueryBuilderController
{
public CustomQueryBuilderController(IQueryBuilderMvcControllerService controllerService) : base(controllerService) { }
public override Task<IActionResult> Invoke()
{
return base.Invoke();
}
}
[ApiExplorerSettings(IgnoreApi = true)]
[Route("DXXRD")]
public class CustomReportDesignerController : ReportDesignerController
{
public CustomReportDesignerController(IReportDesignerMvcControllerService controllerService) : base(controllerService) { }
public override Task<IActionResult> Invoke()
{
return base.Invoke();
}
}
然后在Program中增加
builder.Services.AddMvc().ConfigureApplicationPartManager(x => {
var parts = x.ApplicationParts;
var aspNetCoreReportingAssemblyName = typeof(DevExpress.AspNetCore.Reporting.WebDocumentViewer.WebDocumentViewerController).Assembly.GetName().Name;
var reportingPart = parts.FirstOrDefault(part => part.Name == aspNetCoreReportingAssemblyName);
if (reportingPart != null)
{
parts.Remove(reportingPart);
}
});