2017-12-04 4 views
1

저는 현재 구축중인 서비스에 대한 API를 정의하기 위해 OpenAPI 3.0을 사용하고 있습니다. 다른 구성 요소에서 스키마 구성 요소를 재사용 할 때 문제가 발생합니다. 예를 들어, Note 오브젝트에는 노트를 만든 사람의 Profile 오브젝트가 들어 있습니다. 예상대로 $ref 키워드를 사용하여 Profile 개체를 참조하여 작동합니다. 문제는 프로필에 대한 데이터가없는 예제를 보여줄 때입니다. 아래의 예에서 ref를 배치하면 Profile 구성 요소의 예제 데이터가 아닌 Profile의 실제 OpenAPI 블록이 포함됩니다.오픈 API 상속 예제 데이터

다른 구성 요소에서 구성 요소를 재사용하고 해당 구성 요소에서 예제 세트를 다시 사용하는 방법이 있는지 궁금합니다.

예 :

FullNote: 
    allOf: 
    - $ref: '#/components/schemas/BaseNote' 
    - type: object 
     title: A single note response 
     required: 
     - id 
     - dateCreated 
     - profile 
     properties: 
     id: 
      type: integer 
      format: int32 
     dateCreated: 
      type: integer 
      format: int64 
     profile: 
      type: object 
      $ref: '#/components/schemas/Profile' 
     example: 
     id: 123456789 
     dateCreated: 1509048083045 
     profile: 
      $ref: '#/components/schemas/Profile' 
+0

같은 질문 만 약 OpenAPI를/자신감 2.0 : [? 자신감에 응답 예에서 $ 심판을 사용하는 방법 (https://stackoverflow.com/q/47525254/113116) – Helen

답변

2

$ref 내부를 지원하지 않습니다. - 자신감 UI와 같은이 경우 도구의 속성 예에서 스키마 예제를 빌드합니다

FullNote: 
     allOf: 
     - $ref: '#/components/schemas/BaseNote' 
     - type: object 
      ... 
      example: 
      id: 123456789 
      dateCreated: 1509048083045 
      influencer: 
       prop1: value1 # <---- 
       prop2: value2 

또는, 재산 수준의 예제를 사용할 수 있습니다 전체 예제는 지정된 인라인 할 필요가있다.

FullNote: 
     allOf: 
     - $ref: '#/components/schemas/BaseNote' 
     - type: object 
      ... 
      properties: 
      id: 
       type: integer 
       format: int32 
       example: 123456789  # <---- 
      dateCreated: 
       type: integer 
       format: int64 
       example: 1509048083045 # <---- 
      profile: 
       # This property will use examples from the Profile schema 
       $ref: '#/components/schemas/Profile' 
    Profile: 
     type: object 
     properties: 
     prop1: 
      type: string 
      example: value1 # <----