From 3cbc3a3ed4464fe61f814550857cc62e43c6595b Mon Sep 17 00:00:00 2001 From: Adam Gray Date: Mon, 8 Jun 2020 12:36:35 +0100 Subject: [PATCH] allow unknown string format properties --- .../openapi_parser/properties.py | 4 +--- tests/test_openapi_parser/test_properties.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/openapi_python_client/openapi_parser/properties.py b/openapi_python_client/openapi_parser/properties.py index 66e1920ae..b8cd95479 100644 --- a/openapi_python_client/openapi_parser/properties.py +++ b/openapi_python_client/openapi_parser/properties.py @@ -364,8 +364,6 @@ def _string_based_property( ) -> Union[StringProperty, DateProperty, DateTimeProperty, FileProperty]: """ Construct a Property from the type "string" """ string_format = data.get("format") - if string_format is None: - return StringProperty(name=name, default=data.get("default"), required=required, pattern=data.get("pattern")) if string_format == "date-time": return DateTimeProperty(name=name, required=required, default=data.get("default")) elif string_format == "date": @@ -373,7 +371,7 @@ def _string_based_property( elif string_format == "binary": return FileProperty(name=name, required=required, default=data.get("default")) else: - raise ParseError(data=data, message=f'Unsupported string format:{data["format"]}') + return StringProperty(name=name, default=data.get("default"), required=required, pattern=data.get("pattern")) def property_from_dict(name: str, required: bool, data: Dict[str, Any]) -> Property: diff --git a/tests/test_openapi_parser/test_properties.py b/tests/test_openapi_parser/test_properties.py index 96908c14b..9d03c7d60 100644 --- a/tests/test_openapi_parser/test_properties.py +++ b/tests/test_openapi_parser/test_properties.py @@ -640,8 +640,23 @@ def test__string_based_property_unsupported_format(self, mocker): "type": "string", "format": mocker.MagicMock(), } + StringProperty = mocker.patch(f"{MODULE_NAME}.StringProperty") from openapi_python_client.openapi_parser.properties import _string_based_property - with pytest.raises(ValueError): - _string_based_property(name=name, required=required, data=data) + p = _string_based_property(name=name, required=required, data=data) + + StringProperty.assert_called_once_with(name=name, required=required, pattern=None, default=None) + assert p == StringProperty.return_value + + # Test optional values + StringProperty.reset_mock() + data["default"] = mocker.MagicMock() + data["pattern"] = mocker.MagicMock() + + _string_based_property( + name=name, required=required, data=data, + ) + StringProperty.assert_called_once_with( + name=name, required=required, pattern=data["pattern"], default=data["default"] + )