SwaggerHub将API响应显示为[null]而不是数组

时间:2018-03-06 20:02:22

标签: openapi swaggerhub

我在SwaggerHub中的https://app.swaggerhub.com/apis/PHP-Point-Of-Sale/PHP-Point-Of-Sale/1.0#/customers/get_customers

处有一个OpenAPI 3.0定义

当我认为它应该根据我如何设置OpenAPI定义显示示例值时,示例响应为[null]。

openapi: 3.0.0
...

paths:
  /customers:
    get:
      tags:
        - customers
      summary: Search/list customers
      description: ''
      parameters:
        - name: search
          in: query
          description: Search customers
          required: false
          schema:
            type: string
        - name: search_field
          in: query
          description: Search specific field
          required: false
          schema:
            type: string
            enum:
              - first_name
              - last_name
              - email
              - phone_number
              - account_number
              - custom_field_1
              - custom_field_2
              - custom_field_3
              - custom_field_4
              - custom_field_5
              - custom_field_6
              - custom_field_7
              - custom_field_8
              - custom_field_9
              - custom_field_10
        - name: offset
          in: query
          description: Offset to list customers
          required: false
          schema:
            type: integer
            minimum: 0
            default: 0
        - name: limit
          in: query
          description: Number of customers to get
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
      responses:
        '200':
          description: successful operation
          headers:
            x-total-records:
              description: Total number of results in search
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Customers'
            application/xml:
              schema:
                $ref: '#/components/schemas/Customers'
        '400':
          description: Invalid parameter(s)


components:
  schemas:
    Customer:
      type: object
      allOf:
        - $ref: '#/components/schemas/ExistingPerson'
        - $ref: '#/components/schemas/NewCustomerWithImageUrl'

    Customers:
      type: array
      items:
        $ref: '#/components/schemas/Customer'

    ExistingPerson:
      type: object
      properties:
        person_id:
          type: integer
          format: uuid
          example: 3


    NewCustomerWithImageUrl:
      allOf:
        - $ref: '#/components/schemas/NewCustomer'
        - type: object
          properties:
            image_url:
              type: string
              example: http://www.abc.xyz

    NewCustomer:
      type: object
      allOf:
        - $ref: '#/components/schemas/Person'
        - type: object
          properties:
            company_name:
              type: string
              example: PHP Point Of Sale
            tier_id:
              type: integer
              format: uuid
              example: 0
            account_number:
              type: string
              example: '3333'
            taxable:
              type: boolean
              example: false
            tax_certificate:
              type: string
              example: '1234'
            override_default_tax:
              type: boolean
              example: false
            tax_class_id:
              type: integer
              format: uuid
              example: 0
            balance: 
              type: number
              format: float
              example: 22.99
            credit_limit:
              example: null
            points:
              type: integer
              format: int32
              example: 333
            disable_loyalty:
              type: boolean 
              example: true
            amount_to_spend_for_next_point:
              type: number
              format: float
              readOnly: true
              example: 10.00
            remaining_sales_before_discount:
              type: integer
              format: int32
              readOnly: true
              example: 0
          xml:  
            name: Customer

1 个答案:

答案 0 :(得分:1)

该问题似乎已得到解决,自2018年11月起不再复制。


原始答案:

您的响应示例在http://editor.swagger.io中正确显示(在撰写本文时),使用的是Swagger UI 3.12.0。

看起来SwaggerHub使用旧版本的Swagger UI。您应该contact SwaggerHub Support并要求他们更新到最新的Swagger UI。