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/openapi_python_client/openapi_parser/responses.py b/openapi_python_client/openapi_parser/responses.py index c00cca8ea..f9f373ea3 100644 --- a/openapi_python_client/openapi_parser/responses.py +++ b/openapi_python_client/openapi_parser/responses.py @@ -80,7 +80,7 @@ def constructor(self) -> str: def response_from_dict(*, status_code: int, data: Dict[str, Any]) -> Response: """ Generate a Response from the OpenAPI dictionary representation of it """ if "content" not in data: - raise ParseError(data) + return Response(status_code=status_code) content = data["content"] if "application/json" in content: 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"] + ) diff --git a/tests/test_openapi_parser/test_responses.py b/tests/test_openapi_parser/test_responses.py index 41fc0452b..72eb6c3f3 100644 --- a/tests/test_openapi_parser/test_responses.py +++ b/tests/test_openapi_parser/test_responses.py @@ -95,11 +95,15 @@ def test_constructor(self): class TestResponseFromDict: - def test_response_from_dict_no_content(self): + def test_response_from_dict_no_content(self, mocker): from openapi_python_client.openapi_parser.responses import response_from_dict + Response = mocker.patch(f"{MODULE_NAME}.Response") - with pytest.raises(ValueError): - response_from_dict(status_code=200, data={}) + status_code = mocker.MagicMock(autospec=int) + response = response_from_dict(status_code=status_code, data={}) + + Response.assert_called_once_with(status_code=status_code) + assert response == Response() def test_response_from_dict_unsupported_content_type(self): from openapi_python_client.openapi_parser.responses import response_from_dict