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

SwaggerHub shows API response as [null] instead of array

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

的 SwaggerHub 中有一个 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

该问题似乎已修复,自 2018 年 11 月起不再重现。


原回答:

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

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