Skip to content

Commit 4af2f38

Browse files
authored
Merge branch 'main' into lk-http-timeout
2 parents 8386801 + aa324fc commit 4af2f38

File tree

11 files changed

+597
-576
lines changed

11 files changed

+597
-576
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ Programmatic usage of this project (e.g., importing it as a Python module) and t
1313

1414
The 0.x prefix used in versions for this project is to indicate that breaking changes are expected frequently (several times a year). Breaking changes will increment the minor number, all other changes will increment the patch number. You can track the progress toward 1.0 [here](https://github.com/openapi-generators/openapi-python-client/projects/2).
1515

16+
## 0.13.0
17+
18+
### Breaking Changes
19+
20+
- run `post_hooks` in package directory instead of current directory if meta=none [#696, #697]. Thanks @brenmous and @wallagib!
21+
- Treat leading underscore as a sign of invalid identifier [#703]. Thanks @maxkomarychev!
22+
23+
### Fixes
24+
25+
- generated docstring for `Client.get_headers` function [#713]. Thanks @rtaycher!
26+
1627
## 0.12.3
1728

1829
### Features

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ package_name_override: my_extra_special_package_name
127127

128128
### field_prefix
129129

130-
When generating properties, the `name` attribute of the OpenAPI schema will be used. When the `name` is not a valid
131-
Python identifier (e.g. begins with a number) this string will be prepended. Defaults to "field\_".
130+
When generating properties, the `name` attribute of the OpenAPI schema will be used. When the `name` is not a valid Python identifier (e.g. begins with a number) this string will be prepended. Defaults to "field\_". It will also be used to prefix fields in schema starting with "_" in order to avoid ambiguous semantics.
132131

133132
Example:
134133

end_to_end_tests/golden-record/my_test_api_client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ class AuthenticatedClient(Client):
5959
auth_header_name: str = "Authorization"
6060

6161
def get_headers(self) -> Dict[str, str]:
62-
auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token
6362
"""Get headers to be used in authenticated endpoints"""
63+
auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token
6464
return {self.auth_header_name: auth_header_value, **self.headers}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AModel:
3535
a_nullable_date (Optional[datetime.date]):
3636
a_not_required_date (Union[Unset, datetime.date]):
3737
attr_1_leading_digit (Union[Unset, str]):
38+
attr_leading_underscore (Union[Unset, str]):
3839
required_nullable (Optional[str]):
3940
not_required_nullable (Union[Unset, None, str]):
4041
not_required_not_nullable (Union[Unset, str]):
@@ -62,6 +63,7 @@ class AModel:
6263
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
6364
a_not_required_date: Union[Unset, datetime.date] = UNSET
6465
attr_1_leading_digit: Union[Unset, str] = UNSET
66+
attr_leading_underscore: Union[Unset, str] = UNSET
6567
not_required_nullable: Union[Unset, None, str] = UNSET
6668
not_required_not_nullable: Union[Unset, str] = UNSET
6769
not_required_one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", Unset] = UNSET
@@ -123,6 +125,7 @@ def to_dict(self) -> Dict[str, Any]:
123125
a_not_required_date = self.a_not_required_date.isoformat()
124126

125127
attr_1_leading_digit = self.attr_1_leading_digit
128+
attr_leading_underscore = self.attr_leading_underscore
126129
required_nullable = self.required_nullable
127130
not_required_nullable = self.not_required_nullable
128131
not_required_not_nullable = self.not_required_not_nullable
@@ -207,6 +210,8 @@ def to_dict(self) -> Dict[str, Any]:
207210
field_dict["a_not_required_date"] = a_not_required_date
208211
if attr_1_leading_digit is not UNSET:
209212
field_dict["1_leading_digit"] = attr_1_leading_digit
213+
if attr_leading_underscore is not UNSET:
214+
field_dict["_leading_underscore"] = attr_leading_underscore
210215
if not_required_nullable is not UNSET:
211216
field_dict["not_required_nullable"] = not_required_nullable
212217
if not_required_not_nullable is not UNSET:
@@ -313,6 +318,8 @@ def _parse_one_of_models(data: object) -> Union["FreeFormModel", "ModelWithUnion
313318

314319
attr_1_leading_digit = d.pop("1_leading_digit", UNSET)
315320

321+
attr_leading_underscore = d.pop("_leading_underscore", UNSET)
322+
316323
required_nullable = d.pop("required_nullable")
317324

318325
not_required_nullable = d.pop("not_required_nullable", UNSET)
@@ -447,6 +454,7 @@ def _parse_not_required_nullable_one_of_models(
447454
a_nullable_date=a_nullable_date,
448455
a_not_required_date=a_not_required_date,
449456
attr_1_leading_digit=attr_1_leading_digit,
457+
attr_leading_underscore=attr_leading_underscore,
450458
required_nullable=required_nullable,
451459
not_required_nullable=not_required_nullable,
452460
not_required_not_nullable=not_required_not_nullable,

end_to_end_tests/openapi.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,10 @@
13271327
"title": "Leading Digit",
13281328
"type": "string"
13291329
},
1330+
"_leading_underscore": {
1331+
"title": "Leading Underscore",
1332+
"type": "string"
1333+
},
13301334
"required_nullable": {
13311335
"title": "Required AND Nullable",
13321336
"type": "string",

integration-tests/integration_tests/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ class AuthenticatedClient(Client):
5959
auth_header_name: str = "Authorization"
6060

6161
def get_headers(self) -> Dict[str, str]:
62-
auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token
6362
"""Get headers to be used in authenticated endpoints"""
63+
auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token
6464
return {self.auth_header_name: auth_header_value, **self.headers}

openapi_python_client/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ def _run_command(self, cmd: str) -> None:
155155
)
156156
return
157157
try:
158-
subprocess.run(
159-
cmd, cwd=self.project_dir, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True
160-
)
158+
cwd = self.package_dir if self.meta == MetaType.NONE else self.project_dir
159+
subprocess.run(cmd, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
161160
except CalledProcessError as err:
162161
self.errors.append(
163162
GeneratorError(

openapi_python_client/templates/client.py.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ class AuthenticatedClient(Client):
5656
auth_header_name: str = "Authorization"
5757

5858
def get_headers(self) -> Dict[str, str]:
59-
auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token
6059
"""Get headers to be used in authenticated endpoints"""
61-
return {self.auth_header_name: auth_header_value, **self.headers}
60+
auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token
61+
return {self.auth_header_name: auth_header_value, **self.headers}

openapi_python_client/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PythonIdentifier(str):
1212
def __new__(cls, value: str, prefix: str) -> "PythonIdentifier":
1313
new_value = fix_reserved_words(snake_case(sanitize(value)))
1414

15-
if not new_value.isidentifier():
15+
if not new_value.isidentifier() or value.startswith("_"):
1616
new_value = f"{prefix}{new_value}"
1717
return str.__new__(cls, new_value)
1818

0 commit comments

Comments
 (0)