Skip to content

Commit b8f7722

Browse files
committed
Added CHANGELOG entry for #231, updated formatting and fixed some typing errors.
1 parent 3cd8a65 commit b8f7722

File tree

9 files changed

+27
-8
lines changed

9 files changed

+27
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.7.0 - Unreleased
9+
10+
### Additions
11+
12+
- Added a `--custom-template-path` option for providing custom jinja2 templates (#231 - Thanks @erichulburd!).
13+
814
## 0.6.2 - 2020-11-03
915

1016
### Fixes

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ get an error.
5454

5555
> For more usage details run `openapi-python-client --help` or read [usage](usage.md)
5656
57-
5857
### Using custom templates
5958

60-
This feature leverages Jinja2's [ChoiceLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.ChoiceLoader) and [FileSystemLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.FileSystemLoader). This means you do _not_ need to customize every template. Simply copy the template(s) you want to customize from [the default template directory](openapi_python_client/templates) to your own custom template directory (file names _must_ match exactly) and pass the template directory through the `custom_template_path` flag to the `generate` and `update` commands. For instance,
59+
This feature leverages Jinja2's [ChoiceLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.ChoiceLoader) and [FileSystemLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.FileSystemLoader). This means you do _not_ need to customize every template. Simply copy the template(s) you want to customize from [the default template directory](openapi_python_client/templates) to your own custom template directory (file names _must_ match exactly) and pass the template directory through the `custom-template-path` flag to the `generate` and `update` commands. For instance,
6160

6261
```
6362
openapi-python-client update \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
""" A client library for accessing My Test API """
2+
from .client import AuthenticatedClient, Client
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
""" Contains all the data models used in inputs/outputs """
2+
3+
from .a_model import AModel
4+
from .an_enum import AnEnum
5+
from .an_int_enum import AnIntEnum
6+
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
7+
from .different_enum import DifferentEnum
8+
from .http_validation_error import HTTPValidationError
9+
from .validation_error import ValidationError

end_to_end_tests/regen_golden_record.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
openapi_path = Path(__file__).parent / "openapi.json"
1313

1414
output_path = Path.cwd() / "my-test-api-client"
15-
if sys.argv[1] == "custom":
15+
16+
custom = len(sys.argv) >= 2 and sys.argv[1] == "custom"
17+
if custom:
1618
gr_path = Path(__file__).parent / "golden-record-custom"
1719
else:
1820
gr_path = Path(__file__).parent / "golden-record"
@@ -21,7 +23,7 @@
2123
shutil.rmtree(output_path, ignore_errors=True)
2224
config_path = Path(__file__).parent / "config.yml"
2325

24-
if sys.argv[1] == "custom":
26+
if custom:
2527
result = runner.invoke(
2628
app,
2729
[

end_to_end_tests/test_custom_templates/endpoint_module.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import httpx
21
from typing import Optional
32

3+
import httpx
44

55
Client = httpx.Client
66

openapi_python_client/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import httpcore
1010
import httpx
1111
import yaml
12-
from jinja2 import Environment, PackageLoader, ChoiceLoader, FileSystemLoader
12+
from jinja2 import BaseLoader, ChoiceLoader, Environment, FileSystemLoader, PackageLoader
1313

1414
from openapi_python_client import utils
1515

@@ -35,6 +35,7 @@ def __init__(self, *, openapi: GeneratorData, custom_template_path: Optional[Pat
3535
self.openapi: GeneratorData = openapi
3636

3737
package_loader = PackageLoader(__package__)
38+
loader: BaseLoader
3839
if custom_template_path is not None:
3940
loader = ChoiceLoader(
4041
[

openapi_python_client/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def handle_errors(errors: Sequence[GeneratorError]) -> None:
109109
def generate(
110110
url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"),
111111
path: Optional[pathlib.Path] = typer.Option(None, help="A path to the JSON file"),
112-
custom_template_path: Optional[pathlib.Path] = typer.Option(None, **custom_template_path_options),
112+
custom_template_path: Optional[pathlib.Path] = typer.Option(None, **custom_template_path_options), # type: ignore
113113
) -> None:
114114
""" Generate a new OpenAPI Client library """
115115
from . import create_new_client
@@ -128,7 +128,7 @@ def generate(
128128
def update(
129129
url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"),
130130
path: Optional[pathlib.Path] = typer.Option(None, help="A path to the JSON file"),
131-
custom_template_path: Optional[pathlib.Path] = typer.Option(None, **custom_template_path_options),
131+
custom_template_path: Optional[pathlib.Path] = typer.Option(None, **custom_template_path_options), # type: ignore
132132
) -> None:
133133
""" Update an existing OpenAPI Client library """
134134
from . import update_existing_client

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ isort .\
5858
&& pytest --cov openapi_python_client tests\
5959
"""
6060
regen = "python -m end_to_end_tests.regen_golden_record"
61+
regen_custom = "python -m end_to_end_tests.regen_golden_record custom"
6162
e2e = "pytest openapi_python_client end_to_end_tests"
6263
re = """
6364
task regen\
65+
&& task regen_custom\
6466
&& task e2e\
6567
"""
6668

0 commit comments

Comments
 (0)