Skip to content

Commit aed967c

Browse files
committed
Clean up a few items for #29
1 parent 8fe695d commit aed967c

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

openapi_python_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from pathlib import Path
99
from typing import Any, Dict, Optional
1010

11-
import stringcase
1211
import httpx
1312
import yaml
1413
from jinja2 import Environment, PackageLoader
1514

1615
from openapi_python_client import utils
16+
1717
from .openapi_parser import OpenAPI, import_string_from_reference
1818

1919
__version__ = version(__package__)

openapi_python_client/openapi_parser/properties.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any, ClassVar, Dict, List, Optional
33

44
from openapi_python_client import utils
5+
56
from .reference import Reference
67

78

@@ -16,9 +17,10 @@ class Property:
1617
constructor_template: ClassVar[Optional[str]] = None
1718
_type_string: ClassVar[str]
1819

19-
@property
20-
def python_name(self):
21-
return utils.snake_case(self.name)
20+
python_name: str = field(init=False)
21+
22+
def __post_init__(self) -> None:
23+
self.python_name = utils.snake_case(self.name)
2224

2325
def get_type_string(self) -> str:
2426
""" Get a string representation of type that should be used when declaring this property """

openapi_python_client/templates/model.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class {{ schema.reference.class_name }}:
2222
"{{ property.name }}": self.{{ property.transform() }},
2323
{% endfor %}
2424
{% for property in schema.optional_properties %}
25-
"{{ property.name }}": self.{{ property.transform() }} if self.{{property.python_name}} is not None else None,
25+
"{{ property.name }}": self.{{ property.transform() }} if self.{{ property.python_name }} is not None else None,
2626
{% endfor %}
2727
}
2828

@@ -33,7 +33,7 @@ class {{ schema.reference.class_name }}:
3333
{% if property.constructor_template %}
3434
{% include property.constructor_template %}
3535
{% else %}
36-
{{property.python_name}} = {{property.constructor_from_dict("d")}}
36+
{{ property.python_name }} = {{ property.constructor_from_dict("d") }}
3737
{% endif %}
3838

3939
{% endfor %}

openapi_python_client/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import stringcase
21
import re
32

3+
import stringcase
4+
45

56
def snake_case(value: str) -> str:
67
value = re.sub(r"([A-Z]{2,})([A-Z][a-z]|[ -_]|$)", lambda m: m.group(1).title() + m.group(2), value.strip())

tests/test_end_to_end/test_end_to_end.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ def _compare_directories(first: Path, second: Path, /):
1919
match, mismatch, errors = cmpfiles(first, second, dc.common_files, shallow=False)
2020
if mismatch:
2121
for error in errors:
22-
pytest.fail(f"{first_printable} and {second_printable} had differing files: {mismatch}, first error is {error}", pytrace=False)
22+
pytest.fail(
23+
f"{first_printable} and {second_printable} had differing files: {mismatch}, first error is {error}",
24+
pytrace=False,
25+
)
2326

2427
for sub_path in dc.common_dirs:
2528
_compare_directories(first / sub_path, second / sub_path)
File renamed without changes.

0 commit comments

Comments
 (0)