我有一个使用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, ...)我试过的
这是一个奇怪的错误,但是我已经使用Swagger和Autorest一段时间了,所以我只能假设它要么是一个模糊的bug/配置(可能),要么我忽略了一些愚蠢的东西(可能)。提前感谢您的帮助。
更新
这是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
}
}
}
}发布于 2016-11-16 06:01:28
我可以告诉您如何解决Swagger文件中的问题,并使用最新的版本的AutoRest (https://github.com/Azure/autorest),但我对Swashbuckle一无所知,即它是否可以生成以下内容:
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"x-nullable": false,
"type": "integer",
"format": "int64"
}
}
},注意,我已经写出了一个内联模式,而不是引用"$ref": "#/definitions/Foo"来保持它的简单。重要的是设置"x-nullable": false,它会覆盖默认的为空的行为(预期服务器响应会带来最坏的结果)。在您的示例中,该属性必须添加到引用的模式.../Foo中。
这个特性只有几天的时间了,所以一定要提取最新的AutoRest。
https://stackoverflow.com/questions/39650892
复制相似问题