将 `default` 与 `required` 参数一起用于 OpenAPI
Using `default` with `required` parameters for OpenAPI
Using default
with required
parameters or properties, for example, with path parameters. This does not make sense – if a value is required, the client must always send it, and the default value is never used.
但是当列 IS NOT NULL
并且有 DEFAULT
时,这是数据库的常见习语,不是吗?
为什么这对 OpenAPI 没有意义?
想想函数声明。考虑 JavaScript 字符串方法 indexOf
:
"string".indexOf(searchValue[, fromIndex])
searchValue
参数是必需的,必须始终提供。它没有默认值 - 客户端必须始终提供他们想要查找的子字符串。
fromIndex
参数可选,默认值为0。
现在,如果所需参数 searchValue
有默认值,则意味着不再需要此参数!它现在是可选的,如:
"string".indexOf([searchValue[, fromIndex]])
这就是为什么 defalut
值是可选参数的属性而不是 required
参数的原因。
OpenAPI 中的参数遵循相同的原则。 default
值仅用于文档目的,告诉客户端开发人员如果客户端不提供可选参数,服务器将使用什么值。
Using
default
withrequired
parameters or properties, for example, with path parameters. This does not make sense – if a value is required, the client must always send it, and the default value is never used.
但是当列 IS NOT NULL
并且有 DEFAULT
时,这是数据库的常见习语,不是吗?
为什么这对 OpenAPI 没有意义?
想想函数声明。考虑 JavaScript 字符串方法 indexOf
:
"string".indexOf(searchValue[, fromIndex])
searchValue
参数是必需的,必须始终提供。它没有默认值 - 客户端必须始终提供他们想要查找的子字符串。
fromIndex
参数可选,默认值为0。
现在,如果所需参数 searchValue
有默认值,则意味着不再需要此参数!它现在是可选的,如:
"string".indexOf([searchValue[, fromIndex]])
这就是为什么 defalut
值是可选参数的属性而不是 required
参数的原因。
OpenAPI 中的参数遵循相同的原则。 default
值仅用于文档目的,告诉客户端开发人员如果客户端不提供可选参数,服务器将使用什么值。