Skip to content

Commit 9dbf25b

Browse files
committed
accomodate type changes in werkzeug 3.1.4
1 parent 78a619a commit 9dbf25b

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

openapi_core/datatypes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
from dataclasses import field
77
from typing import Any
88
from typing import Mapping
9+
from typing import Union
910

1011
from werkzeug.datastructures import Headers
1112
from werkzeug.datastructures import ImmutableMultiDict
1213

14+
# Type alias for headers that accepts both Mapping and werkzeug Headers
15+
HeadersType = Union[Mapping[str, Any], Headers]
16+
1317

1418
@dataclass
1519
class RequestParameters:
@@ -27,7 +31,7 @@ class RequestParameters:
2731
"""
2832

2933
query: Mapping[str, Any] = field(default_factory=ImmutableMultiDict)
30-
header: Mapping[str, Any] = field(default_factory=Headers)
34+
header: HeadersType = field(default_factory=Headers)
3135
cookie: Mapping[str, Any] = field(default_factory=ImmutableMultiDict)
3236
path: Mapping[str, Any] = field(default_factory=dict)
3337

openapi_core/protocols.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
from typing import Mapping
55
from typing import Optional
66
from typing import Protocol
7+
from typing import Union
78
from typing import runtime_checkable
89

10+
from werkzeug.datastructures import Headers
11+
912
from openapi_core.datatypes import RequestParameters
1013

14+
# Type alias for headers that accepts both Mapping and werkzeug Headers
15+
HeadersType = Union[Mapping[str, Any], Headers]
16+
1117

1218
@runtime_checkable
1319
class BaseRequest(Protocol):
@@ -109,7 +115,7 @@ def content_type(self) -> str:
109115
"""The content type with parameters and always lowercase."""
110116

111117
@property
112-
def headers(self) -> Mapping[str, Any]:
118+
def headers(self) -> HeadersType:
113119
"""Response headers as Headers."""
114120

115121
@property

openapi_core/validation/response/validators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from openapi_core.casting.schemas import oas30_read_schema_casters_factory
1616
from openapi_core.casting.schemas import oas31_schema_casters_factory
1717
from openapi_core.exceptions import OpenAPIError
18+
from openapi_core.protocols import HeadersType
1819
from openapi_core.protocols import Request
1920
from openapi_core.protocols import Response
2021
from openapi_core.protocols import WebhookRequest
@@ -44,7 +45,7 @@ def _iter_errors(
4445
self,
4546
status_code: int,
4647
data: Optional[bytes],
47-
headers: Mapping[str, Any],
48+
headers: HeadersType,
4849
mimetype: str,
4950
operation: SchemaPath,
5051
) -> Iterator[Exception]:
@@ -91,7 +92,7 @@ def _iter_data_errors(
9192
def _iter_headers_errors(
9293
self,
9394
status_code: int,
94-
headers: Mapping[str, Any],
95+
headers: HeadersType,
9596
operation: SchemaPath,
9697
) -> Iterator[Exception]:
9798
try:
@@ -141,7 +142,7 @@ def _get_data_value(self, data: Optional[bytes]) -> bytes:
141142
return data
142143

143144
def _get_headers(
144-
self, headers: Mapping[str, Any], operation_response: SchemaPath
145+
self, headers: HeadersType, operation_response: SchemaPath
145146
) -> Dict[str, Any]:
146147
if "headers" not in operation_response:
147148
return {}

poetry.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ parse = "*"
7171
openapi-schema-validator = "^0.6.0"
7272
openapi-spec-validator = "^0.7.1"
7373
requests = {version = "*", optional = true}
74-
# werkzeug 3.1.2 changed the definition of Headers
75-
# See https://github.com/python-openapi/openapi-core/issues/938
76-
werkzeug = "<3.1.2"
74+
werkzeug = ">=2.1.0"
7775
jsonschema-path = "^0.3.4"
7876
jsonschema = "^4.23.0"
7977
multidict = {version = "^6.0.4", optional = true}

0 commit comments

Comments
 (0)