Skip to content

feat!(generator): type and id are allowed as attribute names and will not be converted #407

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 2 commits into from
May 3, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class ValidationError:

loc: List[str]
msg: str
type_: str
type: str

def to_dict(self) -> Dict[str, Any]:
loc = self.loc

msg = self.msg
type_ = self.type_
type = self.type

field_dict: Dict[str, Any] = {}
field_dict.update(
{
"loc": loc,
"msg": msg,
"type": type_,
"type": type,
}
)

Expand All @@ -37,12 +37,12 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:

msg = d.pop("msg")

type_ = d.pop("type")
type = d.pop("type")

validation_error = cls(
loc=loc,
msg=msg,
type_=type_,
type=type,
)

return validation_error
2 changes: 1 addition & 1 deletion openapi_python_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def fix_keywords(value: str) -> str:
return value


RESERVED_WORDS = set(dir(builtins)).union({"self"})
RESERVED_WORDS = (set(dir(builtins)) | {"self"}) - {"type", "id"}


def fix_reserved_words(value: str) -> str:
Expand Down
10 changes: 9 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ def test__fix_keywords():


@pytest.mark.parametrize(
"reserved_word, expected", [("self", "self_"), ("int", "int_"), ("dict", "dict_"), ("not_reserved", "not_reserved")]
"reserved_word, expected",
[
("self", "self_"),
("int", "int_"),
("dict", "dict_"),
("not_reserved", "not_reserved"),
("type", "type"),
("id", "id"),
],
)
def test__fix_reserved_words(reserved_word: str, expected: str):
assert utils.fix_reserved_words(reserved_word) == expected
Expand Down