Skip to content

Commit 890411a

Browse files
authored
feat!(generator): type and id are allowed as attribute names and will not be renamed (closes #378)(#407). Thanks @forest-benchling!
1 parent 5805c03 commit 890411a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ class ValidationError:
1111

1212
loc: List[str]
1313
msg: str
14-
type_: str
14+
type: str
1515

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

1919
msg = self.msg
20-
type_ = self.type_
20+
type = self.type
2121

2222
field_dict: Dict[str, Any] = {}
2323
field_dict.update(
2424
{
2525
"loc": loc,
2626
"msg": msg,
27-
"type": type_,
27+
"type": type,
2828
}
2929
)
3030

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

3838
msg = d.pop("msg")
3939

40-
type_ = d.pop("type")
40+
type = d.pop("type")
4141

4242
validation_error = cls(
4343
loc=loc,
4444
msg=msg,
45-
type_=type_,
45+
type=type,
4646
)
4747

4848
return validation_error

openapi_python_client/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def fix_keywords(value: str) -> str:
2323
return value
2424

2525

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

2828

2929
def fix_reserved_words(value: str) -> str:

tests/test_utils.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ def test__fix_keywords():
4646

4747

4848
@pytest.mark.parametrize(
49-
"reserved_word, expected", [("self", "self_"), ("int", "int_"), ("dict", "dict_"), ("not_reserved", "not_reserved")]
49+
"reserved_word, expected",
50+
[
51+
("self", "self_"),
52+
("int", "int_"),
53+
("dict", "dict_"),
54+
("not_reserved", "not_reserved"),
55+
("type", "type"),
56+
("id", "id"),
57+
],
5058
)
5159
def test__fix_reserved_words(reserved_word: str, expected: str):
5260
assert utils.fix_reserved_words(reserved_word) == expected

0 commit comments

Comments
 (0)