[英]How to make Autorest not to generate optional parameters in the extension methods
我为该服务提供了一个庞大的json文件,该文件指定了带有必需参数userName的方法。 但是,Autorest会生成一个扩展方法,此参数是可选的。 这给最终用户带来了困惑,因为他们可以调用该方法而不提供任何肯定会失败的方法。
Autorest产生:
public static object GetUserGet(this XyzService operations, string userName = default(string))
我希望它生成:
public static object GetUserGet(this XyzService operations, string userName)
修改您的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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.