Apiary编辑器上的Swagger将默认值0呈现为null

时间:2018-09-07 11:18:24

标签: yaml swagger-2.0 apiary.io

我正在使用Swagger YAML文件在apiary.io上生成交互式文档。

我注意到一个奇怪的问题,如果我为整数指定默认值0,则交互式文档完全不会渲染它,而是将“ null”显示为默认值。如果我指定一个非零值,它将呈现完美的状态。

示例:

- name: pageNumber
    in: query
    description: The page number, starting at 0.
    required: true
    type: number
    format: int32
    default: 0
- name: pageSize
    in: query
    description: The page size (max number of entities that are displayed in the
      response).
    required: true
    type: integer
    format: int32
    default: 20

?pageNumber=&pageSize=20附加到我的路径上,而应该添加?pageNumber=0&pageSize=20

当我添加如下非零值时:

    - name: pageNumber
    in: query
    description: The page number, starting at 0.
    required: true
    type: number
    format: int32
    default: 1
- name: pageSize
    in: query
    description: The page size (max number of entities that are displayed in the
      response).
    required: true
    type: integer
    format: int32
    default: 20

这很好,并按预期方式附加了?pageNumber=1&pageSize=20

1 个答案:

答案 0 :(得分:1)

海伦的评论解决了我的问题。 在apiary.io上使用YAML进行文档记录时,为了在交互式文档中设置默认值/初始值,需要使用AppDelegate。现在,以下各项将按预期工作:

x-example

成功呈现为 - name: pageNumber in: query description: The page number, starting at 0. required: true type: number format: int32 x-example: 0 - name: pageSize in: query description: The page size (max number of entities that are displayed in the response). required: true type: integer format: int32 x-example: 20