标签: asp.net-core-odata

使用 OData 8.x 和 Route 属性在同一控制器方法上重复端点路由

我遇到了 OData 8.x 和属性路由的问题,其中同一控制器操作生成重复路由。此重复路线导致 Swagger / Swashbuckle 抛出“方法/路径组合冲突”错误。

我已经能够将其简化为Visual Studio 2019 中稍微调整的默认天气预报模板。

// Change name of controller to plural
// Added Route() attribute
// Changed ControllerBase to ODataController (issue happens with ControllerBase too)

[Route("api/[controller]")]
public class WeatherForecastsController : ODataController{

    private static readonly string[] Summaries = new[]
    {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };

    [HttpGet()]
    public IEnumerable<WeatherForecast> Get() {
        var rng = new Random();
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast …
Run Code Online (Sandbox Code Playgroud)

asp.net-core-webapi swashbuckle.aspnetcore asp.net-core-odata

5
推荐指数
1
解决办法
2430
查看次数