Using `default` with `required` parameters for OpenAPI

馋奶兔 提交于 2019-11-28 10:37:02

问题


The documentation says:

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.

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

Why for OpenAPI this makes no sense?


回答1:


Think of function declarations. Consider JavaScript string method indexOf:

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

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.

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

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]])

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


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.



来源:https://stackoverflow.com/questions/49570369/using-default-with-required-parameters-for-openapi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!