代码之家  ›  专栏  ›  技术社区  ›  johni

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

  •  0
  • johni  · 技术社区  · 6 年前

    我有一个asp.net核心项目,它使用NSwag作为它的招摇过市工具。 我的问题如下:

    1. 收集 实体:

    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生成的炫耀文件:

    #

    {
        "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"
                    }
                }
            }
        }
    }
    

    具体来说,我遇到的问题是由于路径声明了两个变量 tenant collection Tenant Collection .

    我希望找到一种方法,用一个属性来修饰DTO类属性,该属性将显式声明参数的名称,比如 [JsonProperty("collection")] (这一特殊情况不影响输出信号)。

    谢谢你的帮助

    0 回复  |  直到 6 年前