【问题标题】:How to make Autorest not to generate optional parameters in the extension methods如何使 Autorest 不在扩展方法中生成可选参数
【发布时间】:2017-12-18 02:24:20
【问题描述】:

我有一个用于服务的 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)

【问题讨论】:

    标签: c# swagger autorest


    【解决方案1】:

    修改您的 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-25
      • 2021-12-05
      • 2011-08-26
      • 2016-02-13
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      • 2016-09-20
      相关资源
      最近更新 更多