Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在NSwag生成的文档中启用“文本/普通”内容类型?_C#_Asp.net Core_Swagger_Nswag - Fatal编程技术网

C# 如何在NSwag生成的文档中启用“文本/普通”内容类型?

C# 如何在NSwag生成的文档中启用“文本/普通”内容类型?,c#,asp.net-core,swagger,nswag,C#,Asp.net Core,Swagger,Nswag,我正在尝试在AspNetCore 3.1 API中创建一个控制器。c,在NSwag.AspNetCore 13.1.3的帮助下。此控制器的目的是接收和返回纯文本而不是json 控制器代码如下所示: [HttpPost] [Route("api/BodyTypes/JsonPlainBody")] [Consumes("text/plain")] [Produces("text/plain")] public string PlainStringBody([FromBody] string

我正在尝试在AspNetCore 3.1 API中创建一个控制器。c,在NSwag.AspNetCore 13.1.3的帮助下。此控制器的目的是接收和返回纯文本而不是json

控制器代码如下所示:

[HttpPost]
[Route("api/BodyTypes/JsonPlainBody")]
[Consumes("text/plain")]    
[Produces("text/plain")]
public string PlainStringBody([FromBody] string content)
{
    return content;
}   
摘录自描述此服务的swagger.json文件:

...
"/api/BodyTypes/JsonPlainBody": {
  "post": {
    "tags": [
      "Acessórios - Operações diversas"
    ],
    "operationId": "Acessorios_PlainStringBody",
    "requestBody": {
      "x-name": "content",
      "content": {
        "application/json": {
          "schema": {
            "type": "string"
          }
        }
      },
      "required": true,
      "x-position": 1
    },
    "responses": {
      "200": {
        "description": "",
        "content": {
          "application/json": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}
...
该控制器在SwaggerUI中的表示不允许我选择内容类型text/plain,因此,以错误的格式生成http请求,导致服务器返回与数据格式415相关的错误-错误:不支持的媒体类型:

在Postman中测试同一控制器时,使用text/plain的内容类型进行编辑,一切正常:


欢迎提供任何帮助。

这看起来像NSwag中的错误,请参阅,这看起来像NSwag中的错误,请参阅和