Skip to content

Commit c12d043

Browse files
committed
Merge branch 'main' into live-generated-code-tests
# Conflicts: # end_to_end_tests/test_end_to_end.py
2 parents 8a11ee0 + e6a597f commit c12d043

File tree

173 files changed

+3555
-1141
lines changed

Some content is hidden

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

173 files changed

+3555
-1141
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
default: patch
3+
---
4+
5+
# Always parse `$ref` as a reference
6+
7+
If additional attributes were included with a `$ref` (for example `title` or `description`), the property could be
8+
interpreted as a new type instead of a reference, usually resulting in `Any` in the generated code.
9+
Now, any sibling properties to `$ref` will properly be ignored, as per the OpenAPI specification.
10+
11+
Thanks @nkrishnaswami!

.changeset/drop_support_for_python_38.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.changeset/type_is_now_a_reserved_field_name.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/checks.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4.2.2
1919
- name: Set up Python
20-
uses: actions/setup-python@v5.3.0
20+
uses: actions/setup-python@v5.4.0
2121
with:
2222
python-version: ${{ matrix.python }}
2323

@@ -51,27 +51,62 @@ jobs:
5151
- name: Run pytest without coverage
5252
if: matrix.os != 'ubuntu-latest'
5353
run: pdm test
54-
env:
55-
TASKIPY: true
5654

5755
- name: Run pytest with coverage
5856
if: matrix.os == 'ubuntu-latest'
5957
run: pdm test_with_coverage
60-
env:
61-
TASKIPY: true
62-
58+
6359
- run: mv .coverage .coverage.${{ matrix.python }}
6460
if: matrix.os == 'ubuntu-latest'
6561

6662
- name: Store coverage report
67-
uses: actions/upload-artifact@v4.4.3
63+
uses: actions/upload-artifact@v4.6.1
6864
if: matrix.os == 'ubuntu-latest'
6965
with:
7066
name: coverage-${{ matrix.python }}
7167
path: .coverage.${{ matrix.python }}
7268
if-no-files-found: error
7369
include-hidden-files: true
7470

71+
test_min_deps:
72+
strategy:
73+
matrix:
74+
os: [ ubuntu-latest, macos-latest, windows-latest ]
75+
runs-on: ${{ matrix.os }}
76+
steps:
77+
- uses: actions/checkout@v4.2.2
78+
- name: Set up Python
79+
uses: actions/setup-python@v5.4.0
80+
with:
81+
python-version: "3.9"
82+
83+
- name: Get Python Version
84+
id: get_python_version
85+
run: echo "python_version=$(python --version)" >> $GITHUB_OUTPUT
86+
shell: bash
87+
88+
- name: Cache dependencies
89+
uses: actions/cache@v4
90+
with:
91+
path: .venv
92+
key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-min-dependencies-${{ hashFiles('**/pdm.lock') }}
93+
restore-keys: |
94+
${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-min-dependencies
95+
- name: Install PDM
96+
run: pip install pdm
97+
98+
- name: Install minimum dependencies
99+
run: pdm install -L pdm.minimal.lock
100+
101+
- name: Run mypy
102+
run: pdm mypy --show-error-codes
103+
104+
- name: Lint
105+
run: pdm run ruff check .
106+
107+
- name: Run unit tests only # snapshots are expected to fail
108+
run: pdm unit_test
109+
75110
coverage:
76111
name: Combine & check coverage
77112
needs: test
@@ -82,7 +117,7 @@ jobs:
82117
with:
83118
python-version: "3.12"
84119
- name: Download coverage reports
85-
uses: actions/download-artifact@v4.1.8
120+
uses: actions/download-artifact@v4.1.9
86121
with:
87122
merge-multiple: true
88123

@@ -107,7 +142,7 @@ jobs:
107142
.venv/bin/python -m coverage report --fail-under=100
108143
109144
- name: Upload HTML report if check failed.
110-
uses: actions/upload-artifact@v4.4.3
145+
uses: actions/upload-artifact@v4.6.1
111146
with:
112147
name: html-report
113148
path: htmlcov
@@ -129,7 +164,7 @@ jobs:
129164
steps:
130165
- uses: actions/checkout@v4.2.2
131166
- name: Set up Python
132-
uses: actions/setup-python@v5.3.0
167+
uses: actions/setup-python@v5.4.0
133168
with:
134169
python-version: "3.9"
135170
- name: Get Python Version

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
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.12.2
21+
uses: pypa/gh-action-pypi-publish@v1.12.4
2222
with:
2323
attestations: true

CHANGELOG.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,94 @@ 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.24.0 (2025-03-03)
17+
18+
### Breaking Changes
19+
20+
#### Support `$ref` in responses
21+
22+
Previously, using a `$ref` to define a response was ignored, the code to call the endpoint was still generated, but
23+
the response would not be parsed. Now, responses defined with `$ref` will be used to generate the response model, which
24+
will parse the response at runtime.
25+
26+
If a `$ref` is incorrect or uses a feature that is not supported by the generator, these endpoints will start failing to
27+
generate.
28+
29+
### Features
30+
31+
#### Make `config` available in custom templates
32+
33+
The configuration options object is now exposed as a variable called `config` in Jinja2 templates.
34+
35+
#### Add `docstrings_on_attributes` config setting
36+
37+
Setting this option to `true` changes the docstring behavior in model classes: for any attribute that have a non-empty `description`, instead of describing the attribute as part of the class's docstring, the description will appear in an individual docstring for that attribute.
38+
39+
## 0.23.1 (2025-01-13)
40+
41+
### Features
42+
43+
- allow Ruff 0.9 (#1192)
44+
45+
## 0.23.0 (2024-12-24)
46+
47+
### Breaking Changes
48+
49+
#### Delete fewer files with `--overwrite`
50+
51+
`--overwrite` will no longer delete the entire output directory before regenerating. Instead, it will only delete
52+
specific, known directories within that directory. Right now, that is only the generated `models` and `api` directories.
53+
54+
Other generated files, like `README.md`, will be overwritten. Extra files and directories outside of those listed above
55+
will be left untouched, so you can any extra modules or files around while still updating `pyproject.toml` automatically.
56+
57+
Closes #1105.
58+
59+
### Features
60+
61+
- Support httpx 0.28 (#1172)
62+
63+
#### Add `generate_all_tags` config option
64+
65+
You can now, optionally, generate **duplicate** endpoint functions/modules using _every_ tag for an endpoint,
66+
not just the first one, by setting `generate_all_tags: true` in your configuration file.
67+
68+
### Fixes
69+
70+
- Support Typer 0.14 and 0.15 (#1173)
71+
72+
#### Fix minimum `attrs` version
73+
74+
The minimum `attrs` dependency version was incorrectly set to 21.3.0. This has been corrected to 22.2.0, the minimum
75+
supported version since `openapi-python-client` 0.19.1.
76+
77+
Closes #1084, thanks @astralblue!
78+
79+
#### Fix compatibility with Pydantic 2.10+
80+
81+
##1176 by @Viicos
82+
83+
Set `defer_build` to models that we know will fail to build, and call `model_rebuild`
84+
in the `__init__.py` file.
85+
86+
## 0.22.0 (2024-11-23)
87+
88+
### Breaking Changes
89+
90+
#### Drop support for Python 3.8
91+
92+
Python 3.8 is no longer supported. "New" 3.9 syntax, like generics on builtin collections, is used both in the generator
93+
and the generated code.
94+
95+
#### `type` is now a reserved field name
96+
97+
Because `type` is used in type annotations now, it is no longer a valid field name. Fields which were previously named
98+
`type` will be renamed to `type_`.
99+
100+
### Features
101+
102+
- Support Ruff 0.8 (#1169)
103+
16104
## 0.21.7 (2024-10-28)
17105

18106
### Fixes

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ class_overrides:
9797
9898
The easiest way to find what needs to be overridden is probably to generate your client and go look at everything in the `models` folder.
9999

100+
### docstrings_on_attributes
101+
102+
By default, when `openapi-python-client` generates a model class, it includes a list of attributes and their
103+
descriptions in the docstring for the class. If you set this option to `true`, then the attribute descriptions
104+
will be put in docstrings for the attributes themselves, and will not be in the class docstring.
105+
106+
```yaml
107+
docstrings_on_attributes: true
108+
```
109+
100110
### literal_enums
101111

102112
By default, `openapi-python-client` generates classes inheriting for `Enum` for enums. It can instead use `Literal`
@@ -108,6 +118,16 @@ literal_enums: true
108118

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

121+
### generate_all_tags
122+
123+
`openapi-python-client` generates module names within the `api` module based on the OpenAPI `tags` of each endpoint.
124+
By default, only the _first_ tag is generated. If you want to generate **duplicate** endpoint functions using _every_ tag
125+
listed, you can enable this option:
126+
127+
```yaml
128+
generate_all_tags: true
129+
```
130+
111131
### project_name_override and package_name_override
112132

113133
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,16 @@
394394
"content": {
395395
"multipart/form-data": {
396396
"schema": {
397-
"$ref": "#/components/schemas/Body_upload_file_tests_upload_post"
397+
"$ref": "#/components/schemas/Body_upload_file_tests_upload_post",
398+
"title": "Body_upload_file_tests_upload_post",
399+
"required": [
400+
"some_file",
401+
"some_object",
402+
"some_nullable_object",
403+
"some_required_number"
404+
],
405+
"properties": {
406+
}
398407
}
399408
}
400409
},
@@ -991,6 +1000,20 @@
9911000
}
9921001
}
9931002
},
1003+
"/responses/reference": {
1004+
"get": {
1005+
"tags": [
1006+
"responses"
1007+
],
1008+
"summary": "Endpoint using predefined response",
1009+
"operationId": "reference_response",
1010+
"responses": {
1011+
"200": {
1012+
"$ref": "#/components/responses/AResponse"
1013+
}
1014+
}
1015+
}
1016+
},
9941017
"/auth/token_with_cookie": {
9951018
"get": {
9961019
"tags": [
@@ -1149,9 +1172,7 @@
11491172
},
11501173
"/tag_with_number": {
11511174
"get": {
1152-
"tags": [
1153-
"1"
1154-
],
1175+
"tags": ["1", "2"],
11551176
"responses": {
11561177
"200": {
11571178
"description": "Success"
@@ -2971,6 +2992,18 @@
29712992
}
29722993
}
29732994
}
2995+
},
2996+
"responses": {
2997+
"AResponse": {
2998+
"description": "OK",
2999+
"content": {
3000+
"application/json": {
3001+
"schema": {
3002+
"$ref": "#/components/schemas/AModel"
3003+
}
3004+
}
3005+
}
3006+
}
29743007
}
29753008
}
29763009
}

0 commit comments

Comments
 (0)