繁体   English   中英

swagger节点ValidationError:“ body”为必填项

[英]swagger node ValidationError: “body” is required

我在另一个使我开始使用Swagger POST的线程中询问了另一个问题,但是在这里我遇到了另一个问题。

这是我的配置json文件中的参数定义

"/people/postTest": {
  "post": {
    "summary": "post test.",
    "description": "Test.",
    "operationId": "postTest",
    "consumes": [
        "application/json"
      ],
    "tags": [
      "test post"
    ],
    "parameters": [
    {
        "in":"body",
        "name":"body",
        "description": "body for the POST request",
        "required":true,
        "schema": {"$ref":"#/definitions/inBody"}
      }

    ] }} 

"definitions": {
     "inBody": {

  "properties": {
    "RequestSystem": {
      "type": "string"
    }}}}

(从一个大文件复制它,因此只占了很小的一部分,但是语法没有问题)

我正在使用CURL发布我的请求

curl -H "Content-Type: application/json" -X POST -d '{"RequestSystem":"IVR"}' http://localhost:8016/people/postTest

这是我尝试启动节点服务器时遇到的验证错误

**ValidationError: "body" is required**

我知道我正在传递“ RequestSystem”参数,但不确定在配置json文件的“参数”中设置参数时我在哪里出错。 任何帮助,将不胜感激。

我认为您需要使required=false

[
{
    "in":"body",
    "name":"body",
    "description": "body for the POST request",
    "required":false,
    "schema": {"$ref":"#/definitions/inBody"}
  }
] 
}
}

试试这个,应该可以。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM