Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using `default` with `required` parameters for OpenAPI

Tags:

openapi

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?

like image 836
Eugen Konkov Avatar asked Apr 19 '26 13:04

Eugen Konkov


1 Answers

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.

like image 162
Helen Avatar answered Apr 22 '26 23:04

Helen