Description
Describe the bug
All parameters defined via reference (introduced in #653) are marked as required.
In the current version of openapi.json, we have this definition:
...
"/parameter-references/{path_param}": {
...
"parameters": [
{
"$ref": "#/components/parameters/string-param"
},
...
"components": {
...
"parameters": {
...
"string-param": {
"name": "string param",
"in": "query",
"required": false,
"style": "form",
"explode": true,
"schema": {
"type": "string"
}
},
...
which generates this code in get_parameter_references_path_param.py:
...
def _get_kwargs(
path_param: str,
*,
client: Client,
string_param: str,
...
but it should instead look like:
...
def _get_kwargs(
path_param: str,
*,
client: Client,
string_param: Union[Unset, None, str] = UNSET,
...
To Reproduce
Steps to reproduce the behavior:
- Define a parameter as a reference (e.g. as under
/parameter-references/{path_param}
) - In the components section, indicate that our parameter is not required (e.g. the one referenced by
"#/components/parameters/string-param"
) - Generate the API
- Notice that the parameter is nevertheless required.
Expected behavior
In general, parameters defined through a reference should be required if and only if their definition in the components section indicates that they're required.
OpenAPI Spec File
https://github.com/openapi-generators/openapi-python-client/blob/f741d8165d713eeb629e839fadc8920209ccfec3/end_to_end_tests/openapi.json
Desktop (please complete the following information):
- OS: macOS 12.6.2
- Python Version: 3.10.2
- openapi-python-client version: 0.13.1
Additional context
I have a small fix which seems to address this.
However, that change calls into question a couple of the arguments to the function parameter_from_data
and some associated tests. Given what we know about the guarantees around arguments passed to that function, I also have another branch with a few deletions.