2014-09-18 15 views
8

मैं स्वैगर 2.0स्वैगर 2.0: प्रकार मॉडल की परिभाषा संपत्ति कैसे घोषित करें?

में टाइप मॉडल की परिभाषा प्रॉपर्टी घोषित करना चाहता हूं क्या यह परिभाषा सही है? (विशेष रूप से प्रकार: StatusObject भाग)

definitions: 
    MyObject: 
    type: "object" 
    properties: 
     id: 
     type: "number" 
     country: 
     type: "string" 
     status: 
     type: StatusObject 
    StatusObject: 
    type: "object" 
    properties: 
     code: 
     type: "number" 
     shortMessage: 
     type: "string" 
     message: 
     type: "string" 

धन्यवाद!

उत्तर

24

अन्य मॉडलों/परिभाषाओं का जिक्र "$ ref" का उपयोग करके किया जाता है।

ऊपर स्निपेट इस तरह दिखना चाहिए:

definitions: 
    MyObject: 
    type: "object" 
    properties: 
     id: 
     type: "number" 
     country: 
     type: "string" 
     status: 
     $ref: StatusObject 
    StatusObject: 
    type: "object" 
    properties: 
     code: 
     type: "number" 
     shortMessage: 
     type: "string" 
     message: 
     type: "string" 

एक और टिप्पणी - आईडी और कोड के लिए प्रकार के रूप में आप "संख्या" का उपयोग कर रहे हैं। "संख्या" में एक दशमलव बिंदु भी हो सकता है जो मुझे यकीन नहीं है कि आप चाहते हैं (विशेष रूप से आईडी के लिए)। यदि आप केवल पूर्ण संख्या चाहते हैं, तो "पूर्णांक" का उपयोग करने पर विचार करें।

+0

धन्यवाद एक बहुत! यह ठीक काम कर रहा है! – JAM

14

स्वैगर 2.0 में:

definitions: 
    MyObject: 
    properties: 
    id: 
     type: "number" 
    country: 
     type: "string" 
    status: 
     $ref: "#/definitions/StatusObject" 
    StatusObject: 
    properties: 
    code: 
    type: "number" 
    shortMessage: 
    type: "string" 
    message: 
    type: "string" 
संबंधित मुद्दे