Skip to content

Commit d2d3e58

Browse files
committed
fix: Nullable header values
1 parent 88adb5c commit d2d3e58

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def _get_kwargs(
1313
*,
1414
string_param: Union[Unset, str] = UNSET,
1515
integer_param: Union[Unset, int] = 0,
16-
header_param: Union[Unset, str] = UNSET,
16+
header_param: Union[None, Unset, str] = UNSET,
1717
cookie_param: Union[Unset, str] = UNSET,
1818
) -> Dict[str, Any]:
1919
headers = {}
@@ -66,7 +66,7 @@ def sync_detailed(
6666
client: Union[AuthenticatedClient, Client],
6767
string_param: Union[Unset, str] = UNSET,
6868
integer_param: Union[Unset, int] = 0,
69-
header_param: Union[Unset, str] = UNSET,
69+
header_param: Union[None, Unset, str] = UNSET,
7070
cookie_param: Union[Unset, str] = UNSET,
7171
) -> Response[Any]:
7272
"""Test different types of parameter references
@@ -75,7 +75,7 @@ def sync_detailed(
7575
path_param (str):
7676
string_param (Union[Unset, str]):
7777
integer_param (Union[Unset, int]):
78-
header_param (Union[Unset, str]):
78+
header_param (Union[None, Unset, str]):
7979
cookie_param (Union[Unset, str]):
8080
8181
Raises:
@@ -107,7 +107,7 @@ async def asyncio_detailed(
107107
client: Union[AuthenticatedClient, Client],
108108
string_param: Union[Unset, str] = UNSET,
109109
integer_param: Union[Unset, int] = 0,
110-
header_param: Union[Unset, str] = UNSET,
110+
header_param: Union[None, Unset, str] = UNSET,
111111
cookie_param: Union[Unset, str] = UNSET,
112112
) -> Response[Any]:
113113
"""Test different types of parameter references
@@ -116,7 +116,7 @@ async def asyncio_detailed(
116116
path_param (str):
117117
string_param (Union[Unset, str]):
118118
integer_param (Union[Unset, int]):
119-
header_param (Union[Unset, str]):
119+
header_param (Union[None, Unset, str]):
120120
cookie_param (Union[Unset, str]):
121121
122122
Raises:

end_to_end_tests/openapi_3.0.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,8 @@
23642364
"in": "header",
23652365
"required": false,
23662366
"schema": {
2367-
"type": "string"
2367+
"type": "string",
2368+
"nullable": true
23682369
}
23692370
},
23702371
"cookie-param": {

end_to_end_tests/openapi_3.1.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,10 @@ info:
24202420
"in": "header",
24212421
"required": false,
24222422
"schema": {
2423-
"type": "string"
2423+
oneOf: [
2424+
type: "string",
2425+
type: "null",
2426+
]
24242427
}
24252428
},
24262429
"cookie-param": {

openapi_python_client/parser/properties/none.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
from attr import define
66

7-
from ...utils import PythonIdentifier
8-
from ..errors import PropertyError
97
from .protocol import PropertyProtocol, Value
8+
from ..errors import PropertyError
9+
from ... import schema as oai
10+
from ...utils import PythonIdentifier
1011

1112

1213
@define
@@ -20,6 +21,11 @@ class NoneProperty(PropertyProtocol):
2021
description: str | None
2122
example: str | None
2223

24+
_allowed_locations: ClassVar[set[oai.ParameterLocation]] = {
25+
oai.ParameterLocation.QUERY,
26+
oai.ParameterLocation.COOKIE,
27+
oai.ParameterLocation.HEADER,
28+
}
2329
_type_string: ClassVar[str] = "None"
2430
_json_type_string: ClassVar[str] = "None"
2531

openapi_python_client/parser/properties/union.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ... import Config
99
from ... import schema as oai
1010
from ...utils import PythonIdentifier
11-
from ..errors import PropertyError
11+
from ..errors import PropertyError, ParseError
1212
from .protocol import PropertyProtocol, Value
1313
from .schemas import Schemas
1414

@@ -169,3 +169,12 @@ def get_lazy_imports(self, *, prefix: str) -> set[str]:
169169
for inner_prop in self.inner_properties:
170170
lazy_imports.update(inner_prop.get_lazy_imports(prefix=prefix))
171171
return lazy_imports
172+
173+
def validate_location(self, location: oai.ParameterLocation) -> ParseError | None:
174+
"""Returns an error if this type of property is not allowed in the given location"""
175+
for inner_prop in self.inner_properties:
176+
if inner_prop.validate_location(location) is not None:
177+
return ParseError(detail=f"{self.get_type_string()} is not allowed in {location}")
178+
if location == oai.ParameterLocation.PATH and not self.required:
179+
return ParseError(detail="Path parameter must be required")
180+
return None

0 commit comments

Comments
 (0)