简体   繁体   English

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

[英]How to make Autorest not to generate optional parameters in the extension methods

I've got a swagger json file for the service that specifies a method with a required parameter userName. 我为该服务提供了一个庞大的json文件,该文件指定了带有必需参数userName的方法。 However, Autorest generates an extension method with this parameter being optional. 但是,Autorest会生成一个扩展方法,此参数是可选的。 That causes confusion for the end user because they can call that method not providing anything which will definitely fail. 这给最终用户带来了困惑,因为他们可以调用该方法而不提供任何肯定会失败的方法。

Autorest generates: Autorest产生:

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

I want it to generate: 我希望它生成:

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

Modify your swagger json set the parameter in question to "required": true that should fix your problem. 修改您的swagger json,将相关参数设置为"required": true应该可以解决您的问题。

Here is an example: 这是一个例子:

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

That example is from this API: http://turoapi.azurewebsites.net/swagger/docs/V1 该示例来自以下API: http : //turoapi.azurewebsites.net/swagger/docs/V1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用可选参数的扩展方法中的方法解析 - Method resolution in extension methods with optional parameters 如何在方法中放置可选参数? - How do I put optional parameters in methods? 如何降级 Autorest 扩展 - 特别是 C# 扩展? - How to downgrade Autorest extensions - specifically C# extension? 如何防止autorest在构造函数中接受null / nullable参数? - How to prevent autorest from accepting null / nullable parameters in the constructors? 如何使 `Func&lt;&gt;` 的一些参数可选? - How to make some parameters of `Func<>` optional? 指定为可选Func &lt;&gt;的扩展方法 - Extension methods specified as an optional Func<> 如何调用具有可选参数的重载方法而编译器没有歧义? - How to call overloaded methods having optional parameters without ambiguity for compiler? 如何制作字典扩展方法? - How to make dictionary extension-methods? 如何在控制器方法中使 JWT 令牌授权可选 - How to make JWT token authorization optional in controller methods 如何通过扩展方法,静态类中的方法以及使用Roslyn的ref / out参数的方法来访问调用 - How to access invocations through extension methods, methods in static classes and methods with ref/out parameters with Roslyn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM