Swagger的allOf显示为未定义

时间:2016-09-23 17:40:50

标签: rest swagger openapi

我已经在https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#models-with-composition中使用了allOf示例,并将它们应用于参数架构和响应架构。但是,我的allOf参数和响应显示为undefined。当使用Pet代替Cat时,它可以正常工作。请让我知道如何使用Swagger的allOf

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 个答案:

答案 0 :(得分:1)

type定义对象中缺少Cat字段,因此招摇编辑器显示undefined

添加type: object,如下所示可以修复它:

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