Skip to content

Commit 0aebefd

Browse files
committed
Formats raise error for other types fix
1 parent bf862ad commit 0aebefd

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

openapi_core/unmarshalling/schemas/unmarshallers.py

+3
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ def unmarshal(self, value: Any) -> Any:
273273
schema_format = self.find_format(value)
274274
if schema_format is None:
275275
return typed
276+
# ignore incompatible formats
277+
if not isinstance(value, str):
278+
return typed
276279
return self.formats_unmarshaller.unmarshal(schema_format, typed)
277280

278281
def get_type_unmarshaller(

tests/integration/unmarshalling/test_unmarshallers.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -374,23 +374,17 @@ def test_string_uuid_invalid(self, unmarshallers_factory):
374374
assert len(exc_info.value.schema_errors) == 1
375375
assert f"is not a 'uuid'" in exc_info.value.schema_errors[0].message
376376

377-
@pytest.mark.xfail(
378-
reason=(
379-
"Formats raise error for other types. "
380-
"See https://github.com/python-openapi/openapi-schema-validator/issues/66"
381-
)
382-
)
383377
@pytest.mark.parametrize(
384378
"type,format,value,expected",
385379
[
386380
("string", "float", "test", "test"),
387381
("string", "double", "test", "test"),
388382
("string", "byte", "test", "test"),
389-
("integer", "date", "10", 10),
390-
("integer", "date-time", "10", 10),
383+
("integer", "date", 10, 10),
384+
("integer", "date-time", 10, 10),
391385
("string", "int32", "test", "test"),
392386
("string", "int64", "test", "test"),
393-
("integer", "password", "10", 10),
387+
("integer", "password", 10, 10),
394388
],
395389
)
396390
def test_formats_ignored(
@@ -1728,7 +1722,8 @@ def test_basic_type_oas30_formats_invalid(
17281722
reason=(
17291723
"OAS 3.0 string type checker allows byte. "
17301724
"See https://github.com/python-openapi/openapi-schema-validator/issues/64"
1731-
)
1725+
),
1726+
strict=True,
17321727
)
17331728
def test_string_format_binary_invalid(self, unmarshallers_factory):
17341729
schema = {
@@ -1748,7 +1743,8 @@ def test_string_format_binary_invalid(self, unmarshallers_factory):
17481743
reason=(
17491744
"Rraises TypeError not SchemaError. "
17501745
"See ttps://github.com/python-openapi/openapi-schema-validator/issues/65"
1751-
)
1746+
),
1747+
strict=True,
17521748
)
17531749
@pytest.mark.parametrize(
17541750
"types,value",
@@ -1928,7 +1924,8 @@ def unmarshallers_factory(self):
19281924
reason=(
19291925
"OpenAPI 3.1 schema validator uses OpenAPI 3.0 format checker."
19301926
"See https://github.com/python-openapi/openapi-core/issues/506"
1931-
)
1927+
),
1928+
strict=True,
19321929
)
19331930
@pytest.mark.parametrize(
19341931
"type,format",

tests/unit/templating/test_paths_finders.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ class BaseTestServerNotFound:
173173
def servers(self):
174174
return []
175175

176-
@pytest.mark.xfail(reason="returns default server")
176+
@pytest.mark.xfail(
177+
reason="returns default server",
178+
strict=True,
179+
)
177180
def test_raises(self, finder):
178181
method = "get"
179182
full_url = "http://petstore.swagger.io/resource"

tests/unit/unmarshalling/test_schema_unmarshallers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ def custom_format_validator(value):
197197
reason=(
198198
"Not registered format raises FormatterNotFoundError"
199199
"See https://github.com/python-openapi/openapi-core/issues/515"
200-
)
200+
),
201+
strict=True,
201202
)
202203
def test_schema_format_validator_format_invalid(
203204
self, schema_unmarshaller_factory, unmarshaller_factory

0 commit comments

Comments
 (0)