簡體   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