2017-03-03 85 views
0

我有這樣的錯誤定義創建直接定義響應對象

"definitions": { 
    "error": { 
     "description": "The error", 
     "properties": { 
      "code": { 
       "description": "The code.", 
       "type": "string" 
      }, 
      "description": { 
       "description": "Uma descrição do erro.", 
       "type": "string" 
      } 
     } 

上,我通過$裁判用這個「錯誤」的定義和它的作品:

"responses": { 
    "400": { 
     "description": "Error.", 
     "schema": { 
      "$ref": "#/definitions/erro" 
     } 

但是我有一個不同的「錯誤「定義在另一個路徑中,並且我想直接在響應中編寫錯誤定義,例如:

"responses": { 
    "400": { 
     "description": "Error.", 
     "schema": { 
      "error": { 
       "description": "The error", 
       "properties": { 
        "code": { 
         "description": "The code.", 
         "type": "string" 
        }, 
        "description": { 
         "description": "Uma descrição do erro.", 
         "type": "string" 
        } 
       } 
     } 

但是它不是工作,與此消息: 「Swagger錯誤。 ?不是有效的響應定義」

我如何能做到這一點

回答

1

你必須改變你響應JSON來:

"400": { 
    "description": "Error.", 
    "schema": { 
     "title": "error", 
     "description": "The error", 
     "type": "object", 
     "properties": { 
      "code": { 
       "type": "string", 
       "description": "The code." 
      }, 
      "description": { 
       "type": "string", 
       "description": "Uma descrição do erro." 
      } 
     } 
    } 
} 
相關問題