ASP.NET MVC 5、Swashbuckle、および AutoRest を使用しているプロジェクトがあります。Autorest を使用して API のクライアントを生成すると、パラメーターが から に変換されますIEnumerable<long>
。IEnumerable<long?>
コントローラーの方法
[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 Spec です
{
"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
}
}
}
}