-
-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support custom template path #231
support custom template path #231
Conversation
63a2c85
to
bbef8b3
Compare
This looks great! My main reason for not adding custom template support thus far was that our existing set of templates and handling thereof is pretty naive (mostly due to my own limited experience with jinja2). In a perfect world, we'll have a well thought out and well documented template "API" that authors of custom templates can reference when writing their own. This probably means a pretty significant refactor of the existing templates. If we want to add this (mostly) as is, I think we just need a big disclaimer that the templating API is very unstable and will break at a later date, so use with care. I think in it's final form we'll want features like:
|
I just added documentation for template usage in the Readme and included the following warning:
I think you bring up good points, but I think a wild west templating API with a Off cuff:
A fully customizable template tree is interesting, but seems complicated in the sense that you would have to think through what variables do you expose to each template (eg imagine iterating through endpoints). Blocks could be useful here. |
@dbanty the above aside, let me know if there are specific TODOs that need to be checked off before this PR is ready for merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple changes and this is good to go:
- Validation on passed in path to prevent potential unhandled exceptions
- Remove the checked in test-reports
openapi_python_client/cli.py
Outdated
@@ -100,6 +100,7 @@ def handle_errors(errors: Sequence[GeneratorError]) -> None: | |||
def generate( | |||
url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"), | |||
path: Optional[pathlib.Path] = typer.Option(None, help="A path to the JSON file"), | |||
custom_template_path: Optional[str] = typer.Option(None, help="A path to a custom template directory"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does FileSystemLoader
do in the event the directory doesn't exist or isn't a directory? We should probably take in a pathlib.Path
here so that Typer can do some validation for us.
@dbanty Done and done. Do you typically squash on merge? Or do we need to reorganize the commits here at all? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks! I squash PRs, so no need to fix up commits here. I'll include this in 0.7.0 with a few other changes I expect to be done by the end of this week.
Sweet thanks @dbanty ! |
This is a WIP, just need to add tests, but before going down that road, I wanted to confirm repo owners would embrace this change.
Pretty well supported method of customization by the folks at Jinja.
TODO:
Solves #202 (and potentially other issues) implicitly.