2017-02-28 19 views
0

我想用swagger來描述我添加到一些代碼中的其餘api。我如何描述這個複雜的json模型在招搖指數

這是我的一個簡單回報。

看過幾個很好的例子,但沒有任何運氣試圖有意義如何將它應用到我的問題。

不同的API調用將包含不同的內容。

如果我知道這個人應該看起來像我一樣能夠找出其他人。

任何人都可以告訴我這個描述應該是什麼樣子嗎?

{  
    "result" : { 
     "content" : { 
     "UNTAINTED_HOST" : "www.google.com", 
     "DATA" : [ 
      "216.58.217.36" 
     ], 
     "IP_or_NAME" : "NAME", 
     "RC" : "true", 
     "FAULT_MSG" : "No Faults" 
     }, 
     "detail" : "Sucessfully terminated your request", 
     "short" : "Done" } 
} 

或者這更簡單的一個:

{ 
    "result" : { 
     "short" : "Done", 
     "detail" : "Sucessfully terminated your request", 
     "content" : "Running" 
    } 
} 

認爲它會看起來像 -

{ 
    "definitions": { 
    "result": { 
     "type": "object", 
     "required": [ 
     "short", "detail", "content" 
     ], 
     "properties": { 
     "type": "array", 
     "items": { 
      "type": "object", 
      "properties": { 
        "content": { 
         "type": "string" 
        }, 
        "detail": { 
         "type": "string" 
        }, 
        "short": { 
         "type": "string" 
        }, 
      } 
     } 
     } 
    } 
    } 
} 

在招搖編輯器嘗試這個...看來我錯過了一些東西。

definitions: 
    results: 
    type: object 
    required: [ result ] 
    properties: 
     result: 
     type: array 
     items: 
      $ref: #/definitions/result 

    result: 
    type: object 
    properties: 
     short: 
     type: string 
     detail: 
     type: string 
     content: 
     type: string 

這似乎工作:

results: 
    type: object 
    required: [ result ] 
    properties: 
     result: 
     type: array 
     items: 
      type: object 
      required: [ short, detail, content ] 
      properties: 
      short: 
       type: string 
      detail: 
       type: string 
      content: 
       type: string 

感謝

+0

比較http://editor.swagger.io/#!/和你的。有幾個頂級項目看起來像缺少了。如果你在編輯器中放棄你的規格,它會很快將它們指出來:即缺少路徑,信息,招搖。 – bitsoflogic

回答

0

這爲我工作:

definitions: 
    result: 
    type: object 
    properties: 
     short: 
     type: string 
     detail: 
     type: string 
     content: 
     type: string 

    results: 
    type: object 
    required: [result] 
    properties: 
     result: 
     type: array 
     items: 
      $ref: '#/definitions/result' 

通知周圍的$ref值的單引號。我原來的帖子中沒有看到這些內容。但是,你沒有提到你所看到的錯誤。如果此答案無效,請更新您的問題並提供更多詳細信息。