Skip to content

allow unknown string format properties #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions openapi_python_client/openapi_parser/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,14 @@ 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":
return DateProperty(name=name, required=required, default=data.get("default"))
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:
Expand Down
19 changes: 17 additions & 2 deletions tests/test_openapi_parser/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)