我有一个名为“ FootballControler”的控制器,具有以下端点:
如您所见,所有端点都试图获取FeedMatch列表。我想要做的就是让他们像这样:
我的解决方案:
[HttpGet]
public List<Match> GetAll()
{
return a list of matches.
}
[HttpGet]
public List<Match> GetByMatchIdAndFeedLeagueId(string externalMatchId, int feedLeagueId)
{
return a list of matches.
}
[HttpGet]
public List<Match> GetByExternalMatchIdAndFeedTypeId(string externalMatchId, int feedTypeId)
{
return a list of matches.
}
[HttpGet]
public List<Match> GetByFeedMatchId(int feedMatchId)
{
return a list of matches.
}
[HttpGet]
public List<Match> GetByMatchId(int feedMatchId)
{
return a list of matches.
}
但是Swashbuckle在Asp.net核心中失败,并带有NotSupportedException异常。
我不想使用这样一种带有可选参数的方法:
[HttpGet]
public List<Match> Get(int? feedMatchId = null, int? feedMatchId = null,string externalMatchId = null ..... )
{
return a list of matches.
}
请帮助我解决此问题。谢谢
使用一个具有多个参数的功能。对于没有值的参数,您的函数将收到null。
[HttpGet]
public List<Match> GetSomething(
[FromQuery] int? externalMatchId,
[FromQuery] int? feedLeagueId,
[FromQuery] int? feedTypeId)
{
if (externalMatchId.HasValue)
{
select by match id
}
...
return a list of matches.
}