如何使Autorest不在扩展方法中生成可选参数

时间:2017-07-13 10:42:13

标签: c# swagger autorest

我有一个服务的swagger json文件,它指定了一个带有必需参数userName的方法。但是,Autorest生成一个扩展方法,此参数是可选的。这会给最终用户造成混淆,因为他们可以调用该方法而不提供肯定会失败的任何东西。

Autorest生成:

public static object GetUserGet(this XyzService operations, string userName = default(string))

我希望它能够生成:

public static object GetUserGet(this XyzService operations, string userName)

1 个答案:

答案 0 :(得分:0)

修改你的swagger json将有问题的参数设置为"required": true,以解决你的问题。

以下是一个例子:

    "paths": {
    "/api/Search": {
        "get": {
            "tags": [ "Search" ],
            "summary": "Get all cars in a given location",
            "operationId": "Search_GetByLocation",
            "consumes": [],
            "produces": [ "application/json", "text/json", "text/html" ],
            "parameters": [
                {
                    "name": "location",
                    "in": "query",
                    "description": "SoFL= 26.16,-80.20",
                    "required": true,
                    "type": "string"
                },
                {
                    "name": "make",
                    "in": "query",
                    "description": "Car make",
                    "required": false,
                    "type": "string"
                }
            ],
            "responses":{ }
        }
    },
    "/api/Stats": {}
},

该示例来自此API: http://turoapi.azurewebsites.net/swagger/docs/V1