2014-09-18 10 views
8

Chcę zadeklarować właściwość definicji typu modelu w Swagger 2.0Swagger 2.0: jak zadeklarować właściwość definicji modelu typu?

Czy ta definicja jest poprawna? (specjalnie typ: część 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" 

Dzięki!

Odpowiedz

24

Nawiązanie do innych modeli/definicji odbywa się za pomocą "$ ref".

Powyższy fragment powinien wyglądać następująco:

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" 

Kolejna uwaga - używasz „numer” jako typ dla identyfikatora i kodu. "liczba" może również mieć separator dziesiętny, którego nie jestem pewien (a zwłaszcza id). Jeśli chcesz tylko liczby całkowite, rozważ użycie "liczby całkowitej".

+0

Dzięki dużo! Działa dobrze! – JAM

14

W 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" 
Powiązane problemy