[英].NET Core swagger query string params
我有一個名為“FootballControler”的 controller,具有以下端點:
如您所見,所有端點都試圖獲取 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.
}
請幫我解決這個問題。 謝謝
使用具有多個參數的 function。 您的 function 將收到無值參數的空值。
[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.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.