Skip to content

Commit d8689c4

Browse files
committed
Merge branch 'main' into fix-696
2 parents ba2971b + f95dbe4 commit d8689c4

File tree

93 files changed

+4011
-776
lines changed

Some content is hidden

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

93 files changed

+4011
-776
lines changed

.github/renovate.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"extends": [
33
"config:base",
44
":semanticCommitTypeAll(chore)"
5-
]
5+
],
6+
"rangeStrategy": "widen"
67
}

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
python: [ "3.7", "3.8", "3.9", "3.10" ]
13+
python: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
1414
os: [ ubuntu-latest, macos-latest, windows-latest ]
1515
runs-on: ${{ matrix.os }}
1616
steps:

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,42 @@ 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.12.3
17+
18+
### Features
19+
20+
- Add `raise_on_unexpected_status` flag to generated `Client` [#593]. Thanks @JamesHinshelwood, @ramnes, @gwenshap, @theFong!
21+
- add `use_path_prefixes_for_title_model_names` config option for simpler model names [#559, #560]. Thanks @rtaycher!
22+
- Support any content type ending in `+json` [#706, #709]. Thanks @XioNoX and @mtovt!
23+
24+
## 0.12.2
25+
26+
### Fixes
27+
28+
- Support Python 3.11.0 (#701)
29+
30+
## 0.12.1
31+
32+
### Fixes
33+
34+
- Version bump due to PyPI error
35+
36+
## 0.12.0
37+
38+
### Breaking Changes
39+
40+
- Change the `Response.status_code` type to the `HTTPStatus` enum [#665]
41+
42+
### Features
43+
44+
- Add `endpoint_collections_by_tag` and `openapi` to the templating globals [#689]. Thanks @paulo-raca!
45+
- Support for recursive and circular references using lazy imports [#670, #338, #466]. Thanks @maz808 & @mtovt!
46+
- Include `__all__` in generated `__init__.py` files [#676, #631, #540, #675]. Thanks @EltonChou!
47+
48+
### Fixes
49+
50+
- If data.type is None but has data.properties, assume type is object [#691, #674]. Thanks @ahuang11!
51+
1652
## 0.11.6
1753

1854
### Features

README.md

Lines changed: 9 additions & 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

@@ -157,5 +156,13 @@ post_hooks:
157156
- "black ."
158157
```
159158

159+
### use_path_prefixes_for_title_model_names
160+
161+
By default, `openapi-python-client` generates class names which include the full path to the schema, including any parent-types. This can result in very long class names like `MyRouteSomeClassAnotherClassResponse`—which is very unique and unlikely to cause conflicts with future API additions, but also super verbose.
162+
163+
If you are carefully curating your `title` properties already to ensure no duplicate class names, you can turn off this prefixing feature by setting `use_path_prefixes_for_title_model_names` to `false` in your config file. This will use the `title` property of any object that has it set _without_ prefixing.
164+
165+
If this option results in conflicts, you will need to manually override class names instead via the `class_overrides` option.
166+
160167
[changelog.md]: CHANGELOG.md
161168
[poetry]: https://python-poetry.org/

end_to_end_tests/golden-record/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ client = AuthenticatedClient(
6161
)
6262
```
6363

64+
There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info.
65+
6466
Things to know:
6567
1. Every path/method combo becomes a Python module with four functions:
6668
1. `sync`: Blocking request that returns parsed data (if successful) or `None`

end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Union
2+
from typing import Any, Dict, Optional, Union
33

44
import httpx
55

6+
from ... import errors
67
from ...client import Client
78
from ...types import UNSET, Response, Unset
89

@@ -32,12 +33,21 @@ def _get_kwargs(
3233
}
3334

3435

35-
def _build_response(*, response: httpx.Response) -> Response[Any]:
36+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
37+
if response.status_code == HTTPStatus.OK:
38+
return None
39+
if client.raise_on_unexpected_status:
40+
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
41+
else:
42+
return None
43+
44+
45+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
3646
return Response(
3747
status_code=HTTPStatus(response.status_code),
3848
content=response.content,
3949
headers=response.headers,
40-
parsed=None,
50+
parsed=_parse_response(client=client, response=response),
4151
)
4252

4353

@@ -50,6 +60,10 @@ def sync_detailed(
5060
Args:
5161
common (Union[Unset, None, str]):
5262
63+
Raises:
64+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
65+
httpx.TimeoutException: If the request takes longer than Client.timeout.
66+
5367
Returns:
5468
Response[Any]
5569
"""
@@ -64,7 +78,7 @@ def sync_detailed(
6478
**kwargs,
6579
)
6680

67-
return _build_response(response=response)
81+
return _build_response(client=client, response=response)
6882

6983

7084
async def asyncio_detailed(
@@ -76,6 +90,10 @@ async def asyncio_detailed(
7690
Args:
7791
common (Union[Unset, None, str]):
7892
93+
Raises:
94+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
95+
httpx.TimeoutException: If the request takes longer than Client.timeout.
96+
7997
Returns:
8098
Response[Any]
8199
"""
@@ -88,4 +106,4 @@ async def asyncio_detailed(
88106
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
89107
response = await _client.request(**kwargs)
90108

91-
return _build_response(response=response)
109+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Union
2+
from typing import Any, Dict, Optional, Union
33

44
import httpx
55

6+
from ... import errors
67
from ...client import Client
78
from ...types import UNSET, Response, Unset
89

@@ -32,12 +33,21 @@ def _get_kwargs(
3233
}
3334

3435

35-
def _build_response(*, response: httpx.Response) -> Response[Any]:
36+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
37+
if response.status_code == HTTPStatus.OK:
38+
return None
39+
if client.raise_on_unexpected_status:
40+
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
41+
else:
42+
return None
43+
44+
45+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
3646
return Response(
3747
status_code=HTTPStatus(response.status_code),
3848
content=response.content,
3949
headers=response.headers,
40-
parsed=None,
50+
parsed=_parse_response(client=client, response=response),
4151
)
4252

4353

@@ -50,6 +60,10 @@ def sync_detailed(
5060
Args:
5161
common (Union[Unset, None, str]):
5262
63+
Raises:
64+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
65+
httpx.TimeoutException: If the request takes longer than Client.timeout.
66+
5367
Returns:
5468
Response[Any]
5569
"""
@@ -64,7 +78,7 @@ def sync_detailed(
6478
**kwargs,
6579
)
6680

67-
return _build_response(response=response)
81+
return _build_response(client=client, response=response)
6882

6983

7084
async def asyncio_detailed(
@@ -76,6 +90,10 @@ async def asyncio_detailed(
7690
Args:
7791
common (Union[Unset, None, str]):
7892
93+
Raises:
94+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
95+
httpx.TimeoutException: If the request takes longer than Client.timeout.
96+
7997
Returns:
8098
Response[Any]
8199
"""
@@ -88,4 +106,4 @@ async def asyncio_detailed(
88106
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
89107
response = await _client.request(**kwargs)
90108

91-
return _build_response(response=response)
109+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Union
2+
from typing import Any, Dict, Optional, Union
33

44
import httpx
55

6+
from ... import errors
67
from ...client import Client
78
from ...models.get_location_header_types_int_enum_header import GetLocationHeaderTypesIntEnumHeader
89
from ...models.get_location_header_types_string_enum_header import GetLocationHeaderTypesStringEnumHeader
@@ -51,12 +52,21 @@ def _get_kwargs(
5152
}
5253

5354

54-
def _build_response(*, response: httpx.Response) -> Response[Any]:
55+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
56+
if response.status_code == HTTPStatus.OK:
57+
return None
58+
if client.raise_on_unexpected_status:
59+
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
60+
else:
61+
return None
62+
63+
64+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
5565
return Response(
5666
status_code=HTTPStatus(response.status_code),
5767
content=response.content,
5868
headers=response.headers,
59-
parsed=None,
69+
parsed=_parse_response(client=client, response=response),
6070
)
6171

6272

@@ -79,6 +89,10 @@ def sync_detailed(
7989
int_enum_header (Union[Unset, GetLocationHeaderTypesIntEnumHeader]):
8090
string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]):
8191
92+
Raises:
93+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
94+
httpx.TimeoutException: If the request takes longer than Client.timeout.
95+
8296
Returns:
8397
Response[Any]
8498
"""
@@ -98,7 +112,7 @@ def sync_detailed(
98112
**kwargs,
99113
)
100114

101-
return _build_response(response=response)
115+
return _build_response(client=client, response=response)
102116

103117

104118
async def asyncio_detailed(
@@ -120,6 +134,10 @@ async def asyncio_detailed(
120134
int_enum_header (Union[Unset, GetLocationHeaderTypesIntEnumHeader]):
121135
string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]):
122136
137+
Raises:
138+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
139+
httpx.TimeoutException: If the request takes longer than Client.timeout.
140+
123141
Returns:
124142
Response[Any]
125143
"""
@@ -137,4 +155,4 @@ async def asyncio_detailed(
137155
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
138156
response = await _client.request(**kwargs)
139157

140-
return _build_response(response=response)
158+
return _build_response(client=client, response=response)

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import datetime
22
from http import HTTPStatus
3-
from typing import Any, Dict, Union
3+
from typing import Any, Dict, Optional, Union
44

55
import httpx
66

7+
from ... import errors
78
from ...client import Client
89
from ...types import UNSET, Response, Unset
910

@@ -56,12 +57,21 @@ def _get_kwargs(
5657
}
5758

5859

59-
def _build_response(*, response: httpx.Response) -> Response[Any]:
60+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
61+
if response.status_code == HTTPStatus.OK:
62+
return None
63+
if client.raise_on_unexpected_status:
64+
raise errors.UnexpectedStatus(f"Unexpected status code: {response.status_code}")
65+
else:
66+
return None
67+
68+
69+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
6070
return Response(
6171
status_code=HTTPStatus(response.status_code),
6272
content=response.content,
6373
headers=response.headers,
64-
parsed=None,
74+
parsed=_parse_response(client=client, response=response),
6575
)
6676

6777

@@ -80,6 +90,10 @@ def sync_detailed(
8090
null_not_required (Union[Unset, None, datetime.datetime]):
8191
not_null_not_required (Union[Unset, None, datetime.datetime]):
8292
93+
Raises:
94+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
95+
httpx.TimeoutException: If the request takes longer than Client.timeout.
96+
8397
Returns:
8498
Response[Any]
8599
"""
@@ -97,7 +111,7 @@ def sync_detailed(
97111
**kwargs,
98112
)
99113

100-
return _build_response(response=response)
114+
return _build_response(client=client, response=response)
101115

102116

103117
async def asyncio_detailed(
@@ -115,6 +129,10 @@ async def asyncio_detailed(
115129
null_not_required (Union[Unset, None, datetime.datetime]):
116130
not_null_not_required (Union[Unset, None, datetime.datetime]):
117131
132+
Raises:
133+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
134+
httpx.TimeoutException: If the request takes longer than Client.timeout.
135+
118136
Returns:
119137
Response[Any]
120138
"""
@@ -130,4 +148,4 @@ async def asyncio_detailed(
130148
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
131149
response = await _client.request(**kwargs)
132150

133-
return _build_response(response=response)
151+
return _build_response(client=client, response=response)

0 commit comments

Comments
 (0)