首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SwaggerHub将API响应显示为[null]而不是数组

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

Stack Overflow用户
提问于 2018-03-06 20:02:21
回答 1查看 1.8K关注 0票数 0

我有一个OpenAPI 3.0的定义在SwaggerHub在客户

当我认为应该根据设置OpenAPI定义的方式显示示例值时,示例响应为null。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-06 20:11:55

这一问题似乎已得到解决,截至2018年11月已不再转载。

原始答案:

您的响应示例在http://editor.swagger.io中正确显示,它(在编写本报告时)使用SwaggerUI3.12.0。

看起来SwaggerHub使用了一个较旧版本的SwaggerHub。您应该使用联系SwaggerHub支持并要求他们更新最新的Swagger。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49139068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档