简体   繁体   中英

swagger node ValidationError: “body” is required

I asked another question in another thread that gave me start on Swagger POST, but here I am stuck with another problem.

Here is my parameter definitions in my config json file

"/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"
    }}}}

(copied it from a big file so only took a small part but there is no issues with syntax)

and I am using CURL to post my request

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

and this is the validation error I am getting when I try to start my node server

**ValidationError: "body" is required**

I know I am passing "RequestSystem" parameter but I am not sure where I am making mistakes in setting up my params in my config json file's "parameters". Any help would be appreciated.

I think you need to make required=false

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

Try this It should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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