2014-09-18 20 views
8

Desidero dichiarare una proprietà di definizione del modello tipo in Swagger 2.0Swagger 2.0: Come dichiarare una proprietà di definizione del modello tipo?

Questa definizione è corretta? (specialmente il tipo: parte 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" 

Grazie!

risposta

24

Il riferimento ad altri modelli/definizioni viene effettuato utilizzando "$ ref".

È possibile che questo frammento dovrebbe essere simile a questo:

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" 

Un altro commento - si sta utilizzando "numero" come tipo per l'ID e il codice. "number" può anche avere un punto decimale che non sono sicuro di volere (specialmente per l'id). Se vuoi solo numeri interi, considera l'utilizzo di "interi".

+0

Thanks a lot! Funziona bene! – JAM

14

In Swagger 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"