Skip to content

Commit b52331c

Browse files
committed
BooleanCaster consistent boolean values fix
1 parent 5d0a7d0 commit b52331c

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

openapi_core/casting/schemas/casters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from openapi_core.casting.schemas.exceptions import CastError
1313
from openapi_core.schema.schemas import get_properties
14-
from openapi_core.util import forcebool
14+
from openapi_core.util import forcebool, BOOLEAN_TRUE_VALUES, BOOLEAN_FALSE_VALUES
1515
from openapi_core.validation.schemas.validators import SchemaValidator
1616

1717

@@ -65,7 +65,7 @@ def validate(self, value: Any) -> None:
6565
if isinstance(value, bool):
6666
return
6767

68-
if value.lower() not in ["false", "true"]:
68+
if value.lower() not in BOOLEAN_TRUE_VALUES + BOOLEAN_FALSE_VALUES:
6969
raise ValueError("not a boolean format")
7070

7171
def cast(self, value: Union[str, bytes]) -> bool:

tests/integration/data/v3.0/petstore.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ paths:
286286
operationId: deleteTag
287287
tags:
288288
- tags
289+
parameters:
290+
- name: x-delete-force
291+
in: header
292+
schema:
293+
type: boolean
294+
required: false
289295
requestBody:
290296
required: false
291297
content:

tests/integration/test_petstore.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,51 @@ def test_delete_tags_no_requestbody(self, spec):
20912091

20922092
assert result.body is None
20932093

2094+
@pytest.mark.parametrize(
2095+
"header_value,expexted_value",
2096+
[
2097+
("y", True),
2098+
("t", True),
2099+
("yes", True),
2100+
("on", True),
2101+
("true", True),
2102+
("1", True),
2103+
("n", False),
2104+
("f", False),
2105+
("no", False),
2106+
("off", False),
2107+
("false", False),
2108+
("0", False),
2109+
],
2110+
)
2111+
def test_delete_tags_header(self, spec, header_value, expexted_value):
2112+
host_url = "http://petstore.swagger.io/v1"
2113+
path_pattern = "/v1/tags"
2114+
headers = {
2115+
"x-delete-force": header_value,
2116+
}
2117+
request = MockRequest(
2118+
host_url,
2119+
"DELETE",
2120+
"/tags",
2121+
headers=headers,
2122+
path_pattern=path_pattern,
2123+
)
2124+
2125+
validate_request(request, spec=spec)
2126+
2127+
result = unmarshal_request(
2128+
request,
2129+
spec=spec,
2130+
cls=V30RequestParametersUnmarshaller,
2131+
)
2132+
2133+
assert result.parameters == Parameters(
2134+
header={
2135+
"x-delete-force": expexted_value,
2136+
},
2137+
)
2138+
20942139
def test_delete_tags_raises_missing_required_response_header(
20952140
self, spec, response_unmarshaller
20962141
):

0 commit comments

Comments
 (0)