我有一个项目使用ASP.NET MVC 5、Swashbuckle和AutoRest。当我使用Autorest为我的API生成客户端时,我的参数从IEnumerable<long>
转换为IEnumerable<long?>
Controller方法
[HttpPost]
public IHttpActionResult Foo([FromBody] IEnumerable<long> ids)
{
// do work
}
生成的 AutoRest 签名
Task<HttpOperationResponse<IList<ResponseModel>> FoWithMessageAsync(IList<long?> ids, ...)
我尝试过的方法
- 使用Get方法。结果是“multi”类型,这是Autorest中已知的一个错误(AutoRest已知的错误)。
- 消除[FromBody]属性
- 将IEnumerable包装在自定义模型中
这是一个奇怪的错误,但我已经使用Swagger和Autorest一段时间了,所以我只能假设它要么是一个晦涩的错误/配置(可能),要么是我漏掉了一些愚蠢的东西(很可能)。提前感谢任何帮助。
更新
这是Swashbuckle生成的Swagger规范。
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "FooBar",
},
"host": "localhost:5000",
"schemes": [
"http"
],
"paths": {
"/api/v1/Foo": {
"post": {
"operationId": "foo",
"consumes": [
"application/json",
"text/json"
],
"produces": [
"application/json",
"text/json"
],
"parameters": [
{
"name": "ids",
"in": "body",
"description": "",
"required": true,
"schema": {
"type": "array",
"items": {
"format": "int64",
"type": "integer"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Foo"
}
}
},
"404": {
"description": "NotFound"
},
"500": {
"description": "InternalServerError"
}
},
"deprecated": false
}
}
}
}