【问题标题】:Only first element of Enum list is displayed instead of Entire list in Swagger仅显示枚举列表的第一个元素,而不是 Swagger 中的整个列表
【发布时间】:2019-06-03 21:33:43
【问题描述】:

下面是python执行生成的YAML

requestBody:
    content:
      application/json:
        schema:
          properties:
            element_ids:
              items:
                type: string
              type: array
            element_type:
              items:
                enum:
                - NC
                - CELL
                type: string
              type: array
            expires_in:
              format: int32
              type: integer
            group_id:
              type: string
          required:
          - element_ids
          - element_type
          - expires_in
          - group_id

我以列表的形式提供了我的枚举值。

我在下面显示的 swagger(3.0.0) 中只看到 NC

【问题讨论】:

    标签: python enums yaml swagger


    【解决方案1】:

    您的规格是正确的。 “示例值”根据您在 OpenAPI 文件中指定的信息显示 示例 请求。 Schema 选项卡上列出了完整的枚举:

    如果要在 JSON 示例中显示 "element_type": ["NC", "CELL"],请将对应的 example 添加到 element_type 属性定义中:

    element_type:
      items:
        enum:
        - NC
        - CELL
        type: string
      type: array
      example: [NC, CELL]  # <----------
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 1970-01-01
      • 2021-03-14
      • 1970-01-01
      相关资源
      最近更新 更多