Swashbuckle Swagger:如何显示模型参数数组的类型?

Swashbuckle Swagger: How to show type of array of models parameter?

我正在使用最新的 2.4 版本 https://github.com/domaindrivendev/Swashbuckle.AspNetCore 为具有 2 个参数的 AspNetCore Controller 方法生成文档:guid 和模型列表。

[HttpPost("MyMethod/{ReferenceId}")]
public async Task<IActionResult> MyMethod(Guid referenceId, List<ApiProfile> passengers)

第一个参数生成正确,但第二个参数不理解类型,只显示数组(无类型)

Passengers
array
(query)

在json中:

"parameters": [
    {
        "name": "passengers",
        "in": "query",
        "description": "",
        "required": false,
        "type": "array",
        "items": {},
        "collectionFormat": "multi"
    },

请注意,类型 ApiProfile 显示在模型部分的底部:

ApiProfile {
    description:    API Object
    Id  string($uuid)
    Email   string
    salutation  string
    firstName   string
    lastName    string
    dateOfBirth string($date-time)
}

在json中:

"definitions": {
    "ApiProfile": {
        "description": "API Object",
        "type": "object",    
        "properties": {"Id": {"format": "uuid","type": "string"},
        "Email": {"type": "string"},
        "salutation": {"type": "string"},
        "firstName": {"type": "string"}
...

我需要有关如何描述要在 Swagger 中显示的请求参数列表类型的建议 UI。

我已经尝试分配 [SwaggerRequestExample(typeof(PeopleRequest), typeof(ListPeopleRequestExample))] 但不确定如何使用 2 个参数进行分配。 我也尝试暂时排除第一个参数,但具有相同的行为。

更新:我创建了一个最小版本,但具有相同的行为。

  [Route("[controller]")]
    public class SwashbuckleTest : Controller
    {
         [HttpPost]
        [Route("{id}")]
        public SwashbuckleTestProfile Post(Guid id, List<SwashbuckleTestProfile> companies)
        {
            return companies.FirstOrDefault();
        }
    }
    public class SwashbuckleTestProfile
    {

        public string Email { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

完整示例可以从 https://github.com/MNF/Samples/tree/master/SwashbuckleExample

加载

您不必做任何特别的事情或描述任何事情。
Swashbuckle 应该照顾好这个...... 闻起来像虫子

我用我的项目测试了类似的东西 Swagger-Net 并且它呈现正常:
http://swagger-net-test.azurewebsites.net/swagger/ui/index?filter=MultiParam#/MultiParamPost/MultiParamPost_Post

    [Route("{id}")]
    public Company Post(Guid id, List<Company> companies)
    {
        return companies.FirstOrDefault();
    }

这是代码输出的相关 JSON:

      {
        "name": "companies",
        "in": "body",
        "required": true,
        "schema": {
          "items": {
            "$ref": "#/definitions/Company"
          },
          "xml": {
            "name": "Company",
            "wrapped": true
          },
          "type": "array"
        }
      }

我想如果你真的想获得 Swashbuckle,你可以使用 IDocumentFilter 并将架构更改为看起来更像我的。

更新: 在使用提供的最小版本后,似乎添加 [FromBody] 对 Swashbuckle.AspNetCore[=15 中的架构进行了重大更改=]

    [Route("{id}")]
    public Company Post(Guid id, [FromBody]List<Company> companies)