Skip to content

Commit 8a11ee0

Browse files
committed
misc fixes
2 parents 15eafe7 + 861ef56 commit 8a11ee0

File tree

213 files changed

+1373
-1357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+1373
-1357
lines changed

Diff for: .changeset/drop_support_for_python_38.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
default: major
3+
---
4+
5+
# Drop support for Python 3.8
6+
7+
Python 3.8 is no longer supported. "New" 3.9 syntax, like generics on builtin collections, is used both in the generator
8+
and the generated code.

Diff for: .changeset/type_is_now_a_reserved_field_name.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
default: major
3+
---
4+
5+
# `type` is now a reserved field name
6+
7+
Because `type` is used in type annotations now, it is no longer a valid field name. Fields which were previously named
8+
`type` will be renamed to `type_`.

Diff for: .github/workflows/checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
- name: Set up Python
132132
uses: actions/[email protected]
133133
with:
134-
python-version: "3.8"
134+
python-version: "3.9"
135135
- name: Get Python Version
136136
id: get_python_version
137137
run: echo "python_version=$(python --version)" >> $GITHUB_OUTPUT

Diff for: .github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
- name: Build
1919
run: hatchling build
2020
- name: Push to PyPI
21-
uses: pypa/gh-action-pypi-publish@v1.10.3
21+
uses: pypa/gh-action-pypi-publish@v1.12.2
2222
with:
2323
attestations: true

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ 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.21.7 (2024-10-28)
17+
18+
### Fixes
19+
20+
- allow required fields list to be specified as empty (#651) (#1149)
21+
- import cast for required const properties, since it's used in the template (#1153)
22+
1623
## 0.21.6 (2024-10-20)
1724

1825
### Features

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ To request a feature:
4141
### Setting up a Dev Environment
4242

4343
1. Make sure you have [PDM](https://pdm-project.org) installed and up to date.
44-
2. Make sure you have a supported Python version (e.g. 3.8) installed.
44+
2. Make sure you have a supported Python version (e.g. 3.13) installed.
4545
3. Use `pdm install` in the project directory to create a virtual environment with the relevant dependencies.
4646

4747
### Writing tests
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Contains methods for accessing the API"""
22

3-
from typing import Type
4-
53
from .bodies import BodiesEndpoints
64
from .config import ConfigEndpoints
75
from .default import DefaultEndpoints
@@ -19,53 +17,53 @@
1917

2018
class MyTestApiClientApi:
2119
@classmethod
22-
def bodies(cls) -> Type[BodiesEndpoints]:
20+
def bodies(cls) -> type[BodiesEndpoints]:
2321
return BodiesEndpoints
2422

2523
@classmethod
26-
def tests(cls) -> Type[TestsEndpoints]:
24+
def tests(cls) -> type[TestsEndpoints]:
2725
return TestsEndpoints
2826

2927
@classmethod
30-
def defaults(cls) -> Type[DefaultsEndpoints]:
28+
def defaults(cls) -> type[DefaultsEndpoints]:
3129
return DefaultsEndpoints
3230

3331
@classmethod
34-
def enums(cls) -> Type[EnumsEndpoints]:
32+
def enums(cls) -> type[EnumsEndpoints]:
3533
return EnumsEndpoints
3634

3735
@classmethod
38-
def responses(cls) -> Type[ResponsesEndpoints]:
36+
def responses(cls) -> type[ResponsesEndpoints]:
3937
return ResponsesEndpoints
4038

4139
@classmethod
42-
def default(cls) -> Type[DefaultEndpoints]:
40+
def default(cls) -> type[DefaultEndpoints]:
4341
return DefaultEndpoints
4442

4543
@classmethod
46-
def parameters(cls) -> Type[ParametersEndpoints]:
44+
def parameters(cls) -> type[ParametersEndpoints]:
4745
return ParametersEndpoints
4846

4947
@classmethod
50-
def tag1(cls) -> Type[Tag1Endpoints]:
48+
def tag1(cls) -> type[Tag1Endpoints]:
5149
return Tag1Endpoints
5250

5351
@classmethod
54-
def location(cls) -> Type[LocationEndpoints]:
52+
def location(cls) -> type[LocationEndpoints]:
5553
return LocationEndpoints
5654

5755
@classmethod
58-
def true_(cls) -> Type[True_Endpoints]:
56+
def true_(cls) -> type[True_Endpoints]:
5957
return True_Endpoints
6058

6159
@classmethod
62-
def naming(cls) -> Type[NamingEndpoints]:
60+
def naming(cls) -> type[NamingEndpoints]:
6361
return NamingEndpoints
6462

6563
@classmethod
66-
def parameter_references(cls) -> Type[ParameterReferencesEndpoints]:
64+
def parameter_references(cls) -> type[ParameterReferencesEndpoints]:
6765
return ParameterReferencesEndpoints
6866

6967
@classmethod
70-
def config(cls) -> Type[ConfigEndpoints]:
68+
def config(cls) -> type[ConfigEndpoints]:
7169
return ConfigEndpoints

Diff for: end_to_end_tests/functional_tests/generated_code_execution/test_arrays.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, ForwardRef, List, Union
1+
from typing import Any, ForwardRef, Union
22

33
from end_to_end_tests.functional_tests.helpers import (
44
assert_model_decode_encode,
@@ -65,9 +65,9 @@ def test_array_of_object(self, ModelWithArrayOfObjects, SimpleObject):
6565
)
6666

6767
def test_type_hints(self, ModelWithArrayOfAny, ModelWithArrayOfInts, ModelWithArrayOfObjects, Unset):
68-
assert_model_property_type_hint(ModelWithArrayOfAny, "array_prop", Union[List[Any], Unset])
69-
assert_model_property_type_hint(ModelWithArrayOfInts, "array_prop", Union[List[int], Unset])
70-
assert_model_property_type_hint(ModelWithArrayOfObjects, "array_prop", Union[List[ForwardRef("SimpleObject")], Unset])
68+
assert_model_property_type_hint(ModelWithArrayOfAny, "array_prop", Union[list[Any], Unset])
69+
assert_model_property_type_hint(ModelWithArrayOfInts, "array_prop", Union[list[int], Unset])
70+
assert_model_property_type_hint(ModelWithArrayOfObjects, "array_prop", Union[list["SimpleObject"], Unset])
7171

7272

7373
@with_generated_client_fixture(
@@ -133,16 +133,16 @@ def test_prefix_items_and_regular_items(self, ModelWithMixedItems, SimpleObject)
133133
)
134134

135135
def test_type_hints(self, ModelWithSinglePrefixItem, ModelWithPrefixItems, ModelWithMixedItems, Unset):
136-
assert_model_property_type_hint(ModelWithSinglePrefixItem, "array_prop", Union[List[str], Unset])
136+
assert_model_property_type_hint(ModelWithSinglePrefixItem, "array_prop", Union[list[str], Unset])
137137
assert_model_property_type_hint(
138138
ModelWithPrefixItems,
139139
"array_prop",
140-
Union[List[Union[ForwardRef("SimpleObject"), str]], Unset],
140+
Union[list[Union[ForwardRef("SimpleObject"), str]], Unset],
141141
)
142142
assert_model_property_type_hint(
143143
ModelWithMixedItems,
144144
"array_prop",
145-
Union[List[Union[ForwardRef("SimpleObject"), str]], Unset],
145+
Union[list[Union[ForwardRef("SimpleObject"), str]], Unset],
146146
)
147147
# Note, this test is asserting the current behavior which, due to limitations of the implementation
148148
# (see: https://github.com/openapi-generators/openapi-python-client/pull/1130), is not really doing

Diff for: end_to_end_tests/functional_tests/generated_code_execution/test_docstrings.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List
1+
from typing import Any
22

33
from end_to_end_tests.functional_tests.helpers import (
44
with_generated_code_import,
@@ -7,12 +7,12 @@
77

88

99
class DocstringParser:
10-
lines: List[str]
10+
lines: list[str]
1111

1212
def __init__(self, item: Any):
1313
self.lines = [line.lstrip() for line in item.__doc__.split("\n")]
1414

15-
def get_section(self, header_line: str) -> List[str]:
15+
def get_section(self, header_line: str) -> list[str]:
1616
lines = self.lines[self.lines.index(header_line)+1:]
1717
return lines[0:lines.index("")]
1818

Diff for: end_to_end_tests/functional_tests/helpers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict
22
import re
3-
from typing import List, Optional
3+
from typing import Optional
44

55
from click.testing import Result
66
import pytest
@@ -12,7 +12,7 @@ def with_generated_client_fixture(
1212
openapi_spec: str,
1313
name: str="generated_client",
1414
config: str="",
15-
extra_args: List[str] = [],
15+
extra_args: list[str] = [],
1616
):
1717
"""Decorator to apply to a test class to create a fixture inside it called 'generated_client'.
1818
@@ -79,7 +79,7 @@ def assert_model_property_type_hint(model_class: Any, name: str, expected_type_h
7979

8080
def inline_spec_should_fail(
8181
openapi_spec: str,
82-
extra_args: List[str] = [],
82+
extra_args: list[str] = [],
8383
config: str = "",
8484
filename_suffix: str = "",
8585
add_missing_sections = True,
@@ -122,7 +122,7 @@ def __init__(self, generated_client: GeneratedClientContext) -> None:
122122
assert "Warning(s) encountered while generating" in output
123123
self.by_schema = {}
124124
self.output = output
125-
bad_schema_regex = "Unable to (parse|process) schema /components/schemas/(\w*)"
125+
bad_schema_regex = "Unable to (parse|process) schema /components/schemas/(\\w*)"
126126
last_name = ""
127127
while True:
128128
if not (match := re.search(bad_schema_regex, output)):

Diff for: end_to_end_tests/generated_client.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66
import sys
77
import tempfile
8-
from typing import Any, List, Optional, Set
8+
from typing import Any, Optional
99

1010
from attrs import define
1111
import pytest
@@ -28,7 +28,7 @@ class GeneratedClientContext:
2828
generator_result: Result
2929
base_module: str
3030
monkeypatch: pytest.MonkeyPatch
31-
old_modules: Optional[Set[str]] = None
31+
old_modules: Optional[set[str]] = None
3232

3333
def __enter__(self) -> "GeneratedClientContext":
3434
self.monkeypatch.syspath_prepend(self.output_path)
@@ -59,7 +59,7 @@ def import_symbol(self, module_path: str, name: str) -> Any:
5959

6060
def _run_command(
6161
command: str,
62-
extra_args: Optional[List[str]] = None,
62+
extra_args: Optional[list[str]] = None,
6363
openapi_document: Optional[str] = None,
6464
url: Optional[str] = None,
6565
config_path: Optional[Path] = None,
@@ -85,7 +85,7 @@ def _run_command(
8585

8686
def generate_client(
8787
openapi_document: str,
88-
extra_args: List[str] = [],
88+
extra_args: list[str] = [],
8989
output_path: str = "my-test-api-client",
9090
base_module: str = "my_test_api_client",
9191
specify_output_path_explicitly: bool = True,
@@ -112,7 +112,7 @@ def generate_client(
112112

113113
def generate_client_from_inline_spec(
114114
openapi_spec: str,
115-
extra_args: List[str] = [],
115+
extra_args: list[str] = [],
116116
config: str = "",
117117
filename_suffix: Optional[str] = None,
118118
base_module: str = "testapi_client",

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/bodies/json_like.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Optional, Union
2+
from typing import Any, Optional, Union
33

44
import httpx
55

@@ -12,10 +12,10 @@
1212
def _get_kwargs(
1313
*,
1414
body: JsonLikeBody,
15-
) -> Dict[str, Any]:
16-
headers: Dict[str, Any] = {}
15+
) -> dict[str, Any]:
16+
headers: dict[str, Any] = {}
1717

18-
_kwargs: Dict[str, Any] = {
18+
_kwargs: dict[str, Any] = {
1919
"method": "post",
2020
"url": "/bodies/json-like",
2121
}

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/bodies/post_bodies_multiple.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Optional, Union
2+
from typing import Any, Optional, Union
33

44
import httpx
55

@@ -19,10 +19,10 @@ def _get_kwargs(
1919
PostBodiesMultipleDataBody,
2020
PostBodiesMultipleFilesBody,
2121
],
22-
) -> Dict[str, Any]:
23-
headers: Dict[str, Any] = {}
22+
) -> dict[str, Any]:
23+
headers: dict[str, Any] = {}
2424

25-
_kwargs: Dict[str, Any] = {
25+
_kwargs: dict[str, Any] = {
2626
"method": "post",
2727
"url": "/bodies/multiple",
2828
}

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/bodies/refs.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Optional, Union
2+
from typing import Any, Optional, Union
33

44
import httpx
55

@@ -12,10 +12,10 @@
1212
def _get_kwargs(
1313
*,
1414
body: AModel,
15-
) -> Dict[str, Any]:
16-
headers: Dict[str, Any] = {}
15+
) -> dict[str, Any]:
16+
headers: dict[str, Any] = {}
1717

18-
_kwargs: Dict[str, Any] = {
18+
_kwargs: dict[str, Any] = {
1919
"method": "post",
2020
"url": "/bodies/refs",
2121
}

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/config/content_type_override.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Optional, Union, cast
2+
from typing import Any, Optional, Union, cast
33

44
import httpx
55

@@ -11,10 +11,10 @@
1111
def _get_kwargs(
1212
*,
1313
body: str,
14-
) -> Dict[str, Any]:
15-
headers: Dict[str, Any] = {}
14+
) -> dict[str, Any]:
15+
headers: dict[str, Any] = {}
1616

17-
_kwargs: Dict[str, Any] = {
17+
_kwargs: dict[str, Any] = {
1818
"method": "post",
1919
"url": "/config/content-type-override",
2020
}

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Optional, Union
2+
from typing import Any, Optional, Union
33

44
import httpx
55

@@ -11,14 +11,14 @@
1111
def _get_kwargs(
1212
*,
1313
common: Union[Unset, str] = UNSET,
14-
) -> Dict[str, Any]:
15-
params: Dict[str, Any] = {}
14+
) -> dict[str, Any]:
15+
params: dict[str, Any] = {}
1616

1717
params["common"] = common
1818

1919
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
2020

21-
_kwargs: Dict[str, Any] = {
21+
_kwargs: dict[str, Any] = {
2222
"method": "get",
2323
"url": "/common_parameters",
2424
"params": params,

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/default/get_models_allof.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Optional, Union
2+
from typing import Any, Optional, Union
33

44
import httpx
55

@@ -9,8 +9,8 @@
99
from ...types import Response
1010

1111

12-
def _get_kwargs() -> Dict[str, Any]:
13-
_kwargs: Dict[str, Any] = {
12+
def _get_kwargs() -> dict[str, Any]:
13+
_kwargs: dict[str, Any] = {
1414
"method": "get",
1515
"url": "/models/allof",
1616
}

0 commit comments

Comments
 (0)