Skip to content

Commit 001b3bf

Browse files
committed
merge from upstream main
1 parent 853eb9c commit 001b3bf

File tree

217 files changed

+1692
-1560
lines changed

Some content is hidden

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

217 files changed

+1692
-1560
lines changed

CHANGELOG.md

+66
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,72 @@ 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.23.0 (2024-12-24)
17+
18+
### Breaking Changes
19+
20+
#### Delete fewer files with `--overwrite`
21+
22+
`--overwrite` will no longer delete the entire output directory before regenerating. Instead, it will only delete
23+
specific, known directories within that directory. Right now, that is only the generated `models` and `api` directories.
24+
25+
Other generated files, like `README.md`, will be overwritten. Extra files and directories outside of those listed above
26+
will be left untouched, so you can any extra modules or files around while still updating `pyproject.toml` automatically.
27+
28+
Closes #1105.
29+
30+
### Features
31+
32+
- Support httpx 0.28 (#1172)
33+
34+
#### Add `generate_all_tags` config option
35+
36+
You can now, optionally, generate **duplicate** endpoint functions/modules using _every_ tag for an endpoint,
37+
not just the first one, by setting `generate_all_tags: true` in your configuration file.
38+
39+
### Fixes
40+
41+
- Support Typer 0.14 and 0.15 (#1173)
42+
43+
#### Fix minimum `attrs` version
44+
45+
The minimum `attrs` dependency version was incorrectly set to 21.3.0. This has been corrected to 22.2.0, the minimum
46+
supported version since `openapi-python-client` 0.19.1.
47+
48+
Closes #1084, thanks @astralblue!
49+
50+
#### Fix compatibility with Pydantic 2.10+
51+
52+
##1176 by @Viicos
53+
54+
Set `defer_build` to models that we know will fail to build, and call `model_rebuild`
55+
in the `__init__.py` file.
56+
57+
## 0.22.0 (2024-11-23)
58+
59+
### Breaking Changes
60+
61+
#### Drop support for Python 3.8
62+
63+
Python 3.8 is no longer supported. "New" 3.9 syntax, like generics on builtin collections, is used both in the generator
64+
and the generated code.
65+
66+
#### `type` is now a reserved field name
67+
68+
Because `type` is used in type annotations now, it is no longer a valid field name. Fields which were previously named
69+
`type` will be renamed to `type_`.
70+
71+
### Features
72+
73+
- Support Ruff 0.8 (#1169)
74+
75+
## 0.21.7 (2024-10-28)
76+
77+
### Fixes
78+
79+
- allow required fields list to be specified as empty (#651) (#1149)
80+
- import cast for required const properties, since it's used in the template (#1153)
81+
1682
## 0.21.6 (2024-10-20)
1783

1884
### Features

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ literal_enums: true
111111

112112
This is especially useful if enum values, when transformed to their Python names, end up conflicting due to case sensitivity or special symbols.
113113

114+
### generate_all_tags
115+
116+
`openapi-python-client` generates module names within the `api` module based on the OpenAPI `tags` of each endpoint.
117+
By default, only the _first_ tag is generated. If you want to generate **duplicate** endpoint functions using _every_ tag
118+
listed, you can enable this option:
119+
120+
```yaml
121+
generate_all_tags: true
122+
```
123+
114124
### project_name_override and package_name_override
115125

116126
Used to change the name of generated client library project/package. If the project name is changed but an override for the package name

end_to_end_tests/__snapshots__/test_end_to_end.ambr

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
# serializer version: 1
2+
# name: test_documents_with_errors[bad-status-code]
3+
'''
4+
Generating /test-documents-with-errors
5+
Warning(s) encountered while generating. Client was generated, but some pieces may be missing
6+
7+
WARNING parsing GET / within default.
8+
9+
Invalid response status code abcdef (not a valid HTTP status code), response will be omitted from generated client
10+
11+
12+
If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose
13+
14+
'''
15+
# ---
216
# name: test_documents_with_errors[circular-body-ref]
317
'''
418
Generating /test-documents-with-errors

end_to_end_tests/baseline_openapi_3.0.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1163,9 +1163,7 @@
11631163
},
11641164
"/tag_with_number": {
11651165
"get": {
1166-
"tags": [
1167-
"1"
1168-
],
1166+
"tags": ["1", "2"],
11691167
"responses": {
11701168
"200": {
11711169
"description": "Success"

end_to_end_tests/baseline_openapi_3.1.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,7 @@ info:
11551155
},
11561156
"/tag_with_number": {
11571157
"get": {
1158-
"tags": [
1159-
"1"
1160-
],
1158+
"tags": ["1", "2"],
11611159
"responses": {
11621160
"200": {
11631161
"description": "Success"

end_to_end_tests/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ class_overrides:
1111
field_prefix: attr_
1212
content_type_overrides:
1313
openapi/python/client: application/json
14+
generate_all_tags: true
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
@@ -13,59 +11,64 @@
1311
from .parameters import ParametersEndpoints
1412
from .responses import ResponsesEndpoints
1513
from .tag1 import Tag1Endpoints
14+
from .tag2 import Tag2Endpoints
1615
from .tests import TestsEndpoints
1716
from .true_ import True_Endpoints
1817

1918

2019
class MyTestApiClientApi:
2120
@classmethod
22-
def bodies(cls) -> Type[BodiesEndpoints]:
21+
def bodies(cls) -> type[BodiesEndpoints]:
2322
return BodiesEndpoints
2423

2524
@classmethod
26-
def tests(cls) -> Type[TestsEndpoints]:
25+
def tests(cls) -> type[TestsEndpoints]:
2726
return TestsEndpoints
2827

2928
@classmethod
30-
def defaults(cls) -> Type[DefaultsEndpoints]:
29+
def defaults(cls) -> type[DefaultsEndpoints]:
3130
return DefaultsEndpoints
3231

3332
@classmethod
34-
def enums(cls) -> Type[EnumsEndpoints]:
33+
def enums(cls) -> type[EnumsEndpoints]:
3534
return EnumsEndpoints
3635

3736
@classmethod
38-
def responses(cls) -> Type[ResponsesEndpoints]:
37+
def responses(cls) -> type[ResponsesEndpoints]:
3938
return ResponsesEndpoints
4039

4140
@classmethod
42-
def default(cls) -> Type[DefaultEndpoints]:
41+
def default(cls) -> type[DefaultEndpoints]:
4342
return DefaultEndpoints
4443

4544
@classmethod
46-
def parameters(cls) -> Type[ParametersEndpoints]:
45+
def parameters(cls) -> type[ParametersEndpoints]:
4746
return ParametersEndpoints
4847

4948
@classmethod
50-
def tag1(cls) -> Type[Tag1Endpoints]:
49+
def tag1(cls) -> type[Tag1Endpoints]:
5150
return Tag1Endpoints
5251

5352
@classmethod
54-
def location(cls) -> Type[LocationEndpoints]:
53+
def tag2(cls) -> type[Tag2Endpoints]:
54+
return Tag2Endpoints
55+
56+
@classmethod
57+
def location(cls) -> type[LocationEndpoints]:
5558
return LocationEndpoints
5659

5760
@classmethod
58-
def true_(cls) -> Type[True_Endpoints]:
61+
def true_(cls) -> type[True_Endpoints]:
5962
return True_Endpoints
6063

6164
@classmethod
62-
def naming(cls) -> Type[NamingEndpoints]:
65+
def naming(cls) -> type[NamingEndpoints]:
6366
return NamingEndpoints
6467

6568
@classmethod
66-
def parameter_references(cls) -> Type[ParameterReferencesEndpoints]:
69+
def parameter_references(cls) -> type[ParameterReferencesEndpoints]:
6770
return ParameterReferencesEndpoints
6871

6972
@classmethod
70-
def config(cls) -> Type[ConfigEndpoints]:
73+
def config(cls) -> type[ConfigEndpoints]:
7174
return ConfigEndpoints
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Contains methods for accessing the API Endpoints"""
2+
3+
import types
4+
5+
from . import get_tag_with_number
6+
7+
8+
class Tag2Endpoints:
9+
@classmethod
10+
def get_tag_with_number(cls) -> types.ModuleType:
11+
return get_tag_with_number
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: "There's something wrong with me"
4+
version: "0.1.0"
5+
paths:
6+
"/":
7+
get:
8+
responses:
9+
"abcdef":
10+
description: "Successful Response"
11+
content:
12+
"application/json":
13+
schema:
14+
const: "Why have a fixed response? I dunno"

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]) # type: ignore
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

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
}

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
}

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
}

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
}

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,

0 commit comments

Comments
 (0)