【问题标题】:How to specify empty string value as default in open api specification for an attribute of type string如何在开放 api 规范中为字符串类型的属性指定空字符串值作为默认值
【发布时间】:2023-03-18 17:10:01
【问题描述】:

我有一个打开的 api yaml 文件,如下所示。我想将空字符串值作为默认值分配给字符串类型属性。这样做的方法是什么

  Test:
type: object
required: ['', '']
properties:
  test1:
    type: string
    default: " "

【问题讨论】:

  • 在不相关的注释上:required: ['', ''] 很可能不是有效的语法。 required 列表应该包含该对象的实际属性名称,例如 required: [test1]

标签: swagger openapi swagger-codegen openapi-generator


【解决方案1】:

肯定是这样的:

默认值:“”

也就是说,里面没有空格。

【讨论】:

  • 它不适用于默认值:"" 用于字符串数据类型。
  • @user3128995 你能澄清一下你所说的“不工作”是什么意思吗?它到底在哪里不起作用?您期望什么结果,实际结果是什么?
【解决方案2】:

如果默认为“”,则 Swagger 字符串类型显示“字符串”。

default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, if type is string, then default can be "foo" but cannot be 1.

这里是问题主题:https://github.com/swagger-api/swagger-codegen/issues/43

【讨论】:

    猜你喜欢
    • 2012-11-28
    • 1970-01-01
    • 2012-12-29
    • 2020-04-12
    • 2019-02-09
    • 2018-05-20
    • 2015-06-24
    • 1970-01-01
    • 2018-04-29
    相关资源
    最近更新 更多