2014-09-18 3 views
8

Swagger 2.0에서 model 유형의 정의 속성을 선언하려고합니다.Swagger 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" 

또 다른 의견 - 당신이 "수"를 사용하는 ID와 코드의 형태로. "number"는 또한 당신이 원한다고 확신 할 수없는 소수점을 가질 수 있습니다 (특히 id의 경우). 정수만 사용하려면 "정수"를 사용하십시오. 자신감 2.0

+0

고마워요! 잘 작동합니다! – JAM

14

:

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