为OpenAPI使用`default`和`required`参数 [英] Using `default` with `required` parameters for OpenAPI

查看:979
本文介绍了为OpenAPI使用`default`和`required`参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说:

defaultrequired参数或属性一起使用,例如,与path参数一起使用.这没有意义-如果需要一个值,则客户端必须始终发送该值,并且永远不会使用默认值.

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时,这是数据库的惯用法吗?

But this is common idiom for databases when column IS NOT NULL and have DEFAULT, is not?

为什么使用OpenAPI没有意义?

Why for OpenAPI this makes no sense?

推荐答案

考虑函数声明.考虑JavaScript字符串方法 indexOf :

Think of function declarations. Consider JavaScript string method indexOf:

"string".indexOf(searchValue[, fromIndex])

searchValue参数是必需的,并且必须始终提供.它没有默认值-客户端必须始终提供他们要查找的子字符串.

The searchValue parameter is required and must always be supplied. It does not have a default value - the client must always provide the substring they want to find.

fromIndex参数是可选的,默认值为0.

The fromIndex parameter is optional, and the default value is 0.

现在,如果必需的参数searchValue具有默认值,则意味着不再需要该参数!现在是可选的,如:

Now, if the required parameter searchValue had a default value, it would mean this parameter is no longer required! It's now optional, as in:

"string".indexOf([searchValue[, fromIndex]])

这就是为什么defalut值是可选参数的属性,而不是required参数的原因.

That's why the defalut value is an attribute of optional parameters and not required parameters.


OpenAPI中的参数遵循相同的原理. default值仅用于文档目的,以告诉客户端开发人员如果客户端不提供可选参数服务器将使用什么值.


Parameters in OpenAPI follow the same principle. The default value is for documentation purposes only, to tell the client developers what value the server will use if a client does not supply an optional parameter.

这篇关于为OpenAPI使用`default`和`required`参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆