[英]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.