我有一个 ASP.NET Web API 2 项目,我已向其中添加了 Swagger - Swashbuckle v5.6.0。一切正常。Swagger UI 按预期呈现我的 API 的测试端点。
我向 API 添加了一个新的控制器。有一个GET带有复杂类型参数的操作。对于复杂类型,Web API 尝试从消息正文中读取值。这是默认行为。
这是我的 GET 操作:
[HttpGet]
[Route("search")]
[ResponseType(typeof(List<SearchModel>))]
public IHttpActionResult Search(SearchModel searchOptions)
{
//....
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
她是我的复杂类型:
public class SearchModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
[DataType(DataType.EmailAddress)]
[EmailAddress]
public string Email { get; set; }
public string AddressLine1 { get; set; }
public string City { get; set; }
public string …Run Code Online (Sandbox Code Playgroud)