2016-09-23 169 views
0

我已將https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#models-with-composition中的allOf示例應用於參數模式和響應模式。但是,我的allOf參數和響應顯示爲未定義。當只使用Pet而不是Cat時,它工作正常。請讓我知道如何使用揚鞭的allOfSwagger的allOf顯示爲undefined

swagger: '2.0' 

# This is your document metadata 
info: 
    version: "0.0.0" 
    title: <enter your title> 

# Describe your paths here 
paths: 
    /test1: 
    # This is a HTTP operation 
    post: 
     description: bla bla 
     parameters: 
     - name: Pet 
      required: true 
      in: body 
      description: The Pet. 
      schema: 
      $ref: '#/definitions/Pet' 
     # Expected responses for this operation: 
     responses: 
     # Response code 
     200: 
      description: Successful response 
      schema: 
      $ref: '#/definitions/Pet' 
    /test2: 
    # This is a HTTP operation 
    post: 
     description: bla bla 
     parameters: 
     - name: Cat 
      required: true 
      in: body 
      description: The cat. 
      schema: 
      $ref: '#/definitions/Cat' 
     # Expected responses for this operation: 
     responses: 
     # Response code 
     200: 
      description: Successful response 
      schema: 
      $ref: '#/definitions/Cat' 
definitions: 
    Pet: 
    type: object 
    discriminator: petType 
    properties: 
     name: 
     type: string 
     petType: 
     type: string 
    required: 
    - name 
    - petType 
    Cat: 
    description: A representation of a cat 
    allOf: 
    - $ref: '#/definitions/Pet' 
    - type: object 
     properties: 
     huntingSkill: 
      type: string 
      description: The measured skill for hunting 
      default: lazy 
      enum: 
      - clueless 
      - lazy 
      - adventurous 
      - aggressive 
     required: 
     - huntingSkill 

enter image description here

enter image description here

回答

1

一個type場中缺少Cat定義對象,因此招搖編輯器顯示undefined

添加type: object如下能解決這個問題:

Cat: 
    type: object 
    description: A representation of a cat 
    allOf: 
+0

謝謝!那讓我瘋狂。 – user1032531