【问题标题】:Optional itemin a swagger yaml definition招摇 yaml 定义中的可选项目
【发布时间】:2017-11-26 14:35:21
【问题描述】:

我在 swagger.yaml 中有以下定义

Content:
    type: object
    properties:
        text:
          type: string
        image:
            ref: "#/definitions/Image"
            allowEmptyValue: true

我得到 Additional properties not allowed: allowEmptyValue as an error

如何使图像成为可选的?即可能只有文字没有图片

【问题讨论】:

    标签: yaml swagger


    【解决方案1】:

    allowEmptyValue 仅适用于查询参数,意思不同—— 包含参数,但其值可能为空,如?param=

    在架构中,默认情况下所有属性都是可选的。您可以通过将某些属性包含在 required 数组中来使它们成为必需的。 required 中未列出的属性被视为可选。

    Content:
        type: object
        properties:
            text:
              type: string
            image:
                ref: "#/definitions/Image"
        # text is required, image is optional
        required:
            - text
    

    【讨论】:

      猜你喜欢
      • 2017-12-19
      • 2018-08-22
      • 1970-01-01
      • 2019-04-01
      • 2021-05-15
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 2021-11-10
      相关资源
      最近更新 更多