Swagger ui .NET中数组参数的描述

时间:2017-05-11 16:22:59

标签: c# asp.net-mvc swagger swagger-ui swashbuckle

我有接收SearchProfilesModel对象的控制器。它由SearchProfiles数组和基类中的几个属性组成。 方法:

[HttpGet]
[ResponseType(typeof(List<UserSearchResult>))]
[Route("SearchWithParams")]
public async Task<HttpResponseMessage> 
    SearchWithParams([FromUri] SearchProfilesModel model)
{
    // Some logic
    return Request.CreateResponse(HttpStatusCode.OK, result);
}

模特课:

public class SearchProfilesModel : LoginRequiredModel
{
    [Required]
    [JsonProperty("search_profiles")]
    public List<SearchProfileViewModel> ProfilesList { get; set; }
}

列出项目类:

public class SearchProfileViewModel
{
    [JsonProperty("name")]
    public string Name { get; set; }
    [JsonProperty("surname")]
    public string Surname { get; set; }
    [JsonProperty("facebook_id")]
    public string FacebookId { get; set; }
    [JsonProperty("email")]
    public string Email { get; set; }
}

我使用Swagger ui(swashbuckle lib)来测试我的控制器,但是当它为这个方法生成帮助页面时,它显示如下: Help page

我的问题是 - 我能以某种方式在参数中显示列表项的结构(来自SearchProfileViewModel)吗?如果我能 - 怎么样? 附: - 对不起我的英语,这不是我的母语。

1 个答案:

答案 0 :(得分:0)

你的对象的结构在生成的doc中,看看我的: http://swashbuckletest.azurewebsites.net/swagger/docs/v1

{
"swagger": "2.0",
"info": {...},
"host": "swashbuckletest.azurewebsites.net",
"schemes": [...],
"paths": {...},
"definitions": {
    "Data": {
        "type": "object",
        "properties": {
            "integ": {
                "format": "int32",
                "type": "integer",
                "example": 123
            },
            "doub": {
                "format": "double",
                "type": "number",
                "example": 9858.216
            },
            "boolea": {
                "type": "boolean"
            },
            "guid": {
                "format": "uuid",
                "type": "string",
                "example": "f5849915-43c8-434c-92a7-7383d1acb631"
            },
            "date": {
                "format": "date-time",
                "type": "string"
            }
        }
    },
...