Skip to content

Commit 130bab8

Browse files
author
Barry Barrette
committed
Merge remote-tracking branch 'upstream/main'
2 parents d6da44a + d681971 commit 130bab8

File tree

9 files changed

+231
-168
lines changed

9 files changed

+231
-168
lines changed

.github/workflows/checks.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
if: matrix.os == 'ubuntu-latest'
6161

6262
- name: Store coverage report
63-
uses: actions/[email protected].1
63+
uses: actions/[email protected].2
6464
if: matrix.os == 'ubuntu-latest'
6565
with:
6666
name: coverage-${{ matrix.python }}
@@ -117,7 +117,7 @@ jobs:
117117
with:
118118
python-version: "3.12"
119119
- name: Download coverage reports
120-
uses: actions/download-artifact@v4.1.9
120+
uses: actions/download-artifact@v4.2.1
121121
with:
122122
merge-multiple: true
123123

@@ -142,7 +142,7 @@ jobs:
142142
.venv/bin/python -m coverage report --fail-under=100
143143
144144
- name: Upload HTML report if check failed.
145-
uses: actions/[email protected].1
145+
uses: actions/[email protected].2
146146
with:
147147
name: html-report
148148
path: htmlcov

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ 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.2 (2025-03-22)
17+
18+
### Fixes
19+
20+
#### Make lists of models and enums work correctly in custom templates
21+
22+
Lists of model and enum classes should be available to custom templates via the Jinja
23+
variables `openapi.models` and `openapi.enums`, but these were being passed in a way that made
24+
them always appear empty. This has been fixed so a custom template can now iterate over them.
25+
26+
Closes #1188.
27+
1628
## 0.24.1 (2025-03-15)
1729

1830
### Features
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Testing that we can access model-related information via Jinja variables.
2+
3+
# To avoid having to update this file in the golden record every time the test specs are changed,
4+
# we won't include all the classes in this output - we'll just look for one of them.
5+
6+
# Using "alls"
7+
# AModel
8+
9+
# Using "imports"
10+
# from .a_model import AModel
11+
12+
# Using "openapi.models"
13+
# AModel (a_model)
14+
15+
# Using "openapi.enums"
16+
# AnEnum (an_enum)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
# Testing that we can access model-related information via Jinja variables.
3+
4+
# To avoid having to update this file in the golden record every time the test specs are changed,
5+
# we won't include all the classes in this output - we'll just look for one of them.
6+
7+
# Using "alls"
8+
{% for name in alls %}
9+
{% if name == "AModel" %}
10+
# {{ name }}
11+
{% endif %}
12+
{% endfor %}
13+
14+
# Using "imports"
15+
{% for import in imports %}
16+
{% if import.endswith("import AModel") %}
17+
# {{ import }}
18+
{% endif %}
19+
{% endfor %}
20+
21+
# Using "openapi.models"
22+
{% for model in openapi.models %}
23+
{% if model.class_info.name == "AModel" %}
24+
# {{ model.class_info.name }} ({{ model.class_info.module_name }})
25+
{% endif %}
26+
{% endfor %}
27+
28+
# Using "openapi.enums"
29+
{% for enum in openapi.enums %}
30+
{% if enum.class_info.name == "AnEnum" %}
31+
# {{ enum.class_info.name }} ({{ enum.class_info.module_name }})
32+
{% endif %}
33+
{% endfor %}

end_to_end_tests/test_end_to_end.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,15 @@ def test_custom_templates():
185185
{}
186186
) # key: path relative to generated directory, value: expected generated content
187187
api_dir = Path("my_test_api_client").joinpath("api")
188+
models_dir = Path("my_test_api_client").joinpath("models")
188189
golden_tpls_root_dir = Path(__file__).parent.joinpath(
189190
"custom-templates-golden-record"
190191
)
191192

192193
expected_difference_paths = [
193194
Path("README.md"),
194195
api_dir.joinpath("__init__.py"),
196+
models_dir.joinpath("__init__.py"),
195197
]
196198

197199
for expected_difference_path in expected_difference_paths:

integration-tests/pdm.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openapi_python_client/parser/openapi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ class GeneratorData:
508508
title: str
509509
description: Optional[str]
510510
version: str
511-
models: Iterator[ModelProperty]
511+
models: list[ModelProperty]
512512
errors: list[ParseError]
513513
endpoint_collections_by_tag: dict[utils.PythonIdentifier, EndpointCollection]
514-
enums: Iterator[Union[EnumProperty, LiteralEnumProperty]]
514+
enums: list[Union[EnumProperty, LiteralEnumProperty]]
515515

516516
@staticmethod
517517
def from_dict(data: dict[str, Any], *, config: Config) -> Union["GeneratorData", GeneratorError]:
@@ -546,10 +546,10 @@ def from_dict(data: dict[str, Any], *, config: Config) -> Union["GeneratorData",
546546
config=config,
547547
)
548548

549-
enums = (
549+
enums = [
550550
prop for prop in schemas.classes_by_name.values() if isinstance(prop, (EnumProperty, LiteralEnumProperty))
551-
)
552-
models = (prop for prop in schemas.classes_by_name.values() if isinstance(prop, ModelProperty))
551+
]
552+
models = [prop for prop in schemas.classes_by_name.values() if isinstance(prop, ModelProperty)]
553553

554554
return GeneratorData(
555555
title=openapi.info.title,

0 commit comments

Comments
 (0)