gpt4 book ai didi

c# - 来自 Swagger 文档的 AutoRest - IEnumerable 生成为 IEnumerable

转载 作者:行者123 更新时间:2023-11-30 18:19:07 26 4
gpt4 key购买 nike

我有一个使用 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, ...)

我尝试过的

  • 使用获取方法。导致“多”类型,这是 Autorest 中的一个已知错误 known bug in 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
}
}
}
}

最佳答案

我可以告诉您如何在 Swagger 文件中以及使用最新 版本的 AutoRest (https://github.com/Azure/autorest) 解决您的问题,但我对 Swashbuckle 毫 headless 绪,即它是否可以生成以下内容:

"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"x-nullable": false,
"type": "integer",
"format": "int64"
}
}
},

请注意,为了简单起见,我拼出了内联模式而不是引用 "$ref": "#/definitions/Foo"。重要的是设置 "x-nullable": false,它会覆盖默认的可空行为(期望服务器响应最坏)。在您的情况下,必须将属性添加到引用的架构 .../Foo

此功能才推出几天,因此请务必使用最新的 AutoRest。

关于c# - 来自 Swagger 文档的 AutoRest - IEnumerable<long> 生成为 IEnumerable<long?>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39650892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com