NSwag(Swagger)创建大小写敏感的swagger文件,导致参数名称不一致

时间:2019-01-14 13:27:03

标签: c# asp.net asp.net-mvc swagger nswag

我有一个asp.net核心项目,该项目使用NSwag作为其Swagger工具。 我遇到的问题如下:

  1. 我有一个Dto类来描述 Collection 实体:

namespace SchedulerApi.Entities
{
    public class JobCollectionDtoV2
    {
        [Required]
        [FromRoute]
        [RegularExpression("^[a-z][a-z0-9]+$")]
        [StringLength(maximumLength: 24, MinimumLength = 3)]
        public string Collection { get; set; }

        [Required]
        [FromRoute]
        [RegularExpression("^[a-z][a-z0-9]+$")]
        [StringLength(maximumLength: 24, MinimumLength = 3)]
        public string Tenant { get; set; }
    }
}
  1. 以下API用于添加集合

[HttpPut]
[Route("tenants/{tenant}/collections/{collection}")]
[SwaggerResponse(typeof(JobCollectionDtoV2))]
public async Task<IActionResult> CreateTask(JobCollectionDtoV2 collectionParams)
{
}
  1. 这是NSwag生成的Swagger文件:

{
    "put": {
        "tags": [
            "JobCollectionsControllerV2"
        ],
        "operationId": "JobCollectionsControllerV2_CreateTask",
        "consumes": [
            "application/json-patch+json",
            "application/json",
            "text/json",
            "application/*+json"
        ],
        "parameters": [
            {
                "type": "string",
                "name": "Collection",
                "in": "path",
                "required": true,
                "maxLength": 24,
                "minLength": 3,
                "pattern": "^[a-z][a-z0-9]+$",
                "x-nullable": true
            },
            {
                "type": "string",
                "name": "Tenant",
                "in": "path",
                "required": true,
                "maxLength": 24,
                "minLength": 3,
                "pattern": "^[a-z][a-z0-9]+$",
                "x-nullable": true
            },
            {
                "name": "CollectionDetails",
                "in": "body",
                "required": true,
                "schema": {
                    "$ref": "#/definitions/JobCollectionDetails"
                },
                "x-nullable": false
            }
        ],
        "responses": {
            "200": {
                "x-nullable": true,
                "description": "",
                "schema": {
                    "$ref": "#/definitions/JobCollectionDtoV2"
                }
            }
        }
    }
}

我遇到的具体问题是由于以下事实引起的:路径以小写形式声明了两个变量tenantcollection,而DTO类以大写形式{{1}声明了相应的属性}和Tenant

我希望找到一种用显式声明参数名称的属性来修饰DTO类属性的方法,例如Collection(此特定变量不会影响输出Swagger)。

感谢您的帮助

0 个答案:

没有答案