-
-
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
Extending/adding templates #171
Comments
Trying to separate out some of the improvements you're making manually from some of the potential solutions so we can brainstorm about them individually (since some may be easier to solve than others). So it looks like the things you're doing are:
Does that about cover it? As far as some possible solutions, I do like the idea of customizable templates but I think such a thing would be pretty far off. It would mean we need a stable documented API for how we render jinja templates- so this is probably a post-1.0 feature once the project itself is fairly stable. This would open up all sorts of doors though- even generating clients in different languages if we really wanted to. Of course then we're effectively becoming a full alternative to the Java openapi generator which I'm not sure is a responsibility I want 😅. Flattening arguments in general feels like something we could achieve as a feature without too much work, though we'd have to be careful when there are other params (headers, query) which might have conflicting names. The shared client in a class model is something I considered early on but ultimately decided on a more functional style for this project. This certainly has the downside of being more verbose. It does seem like a good idea to offer an alternative set of templates that's more object oriented for those who prefer that style. If we support more paradigms then we can lean more into each. Combining multiple documents into one client is 100% something I want to do at some point. We use a lot of microservices which, like what you describe, often have a lot of overlap. I think it's going to take a lot of care to get this one right without generating errors all over the place. Maybe after my brain cools off a bit from the 0.6 refactor 🥵. I believe this could be broken up into a few independent issues so we can bite off one at a time:
And of course anything I didn't notice as well 👍. Thanks for all your input, as always you give me a lot to think about. |
I think we have separate issues for each feature request in here now so I'm going to close this big one:
|
Is your feature request related to a problem? Please describe.
The OpenAPI specs I'm generating clients from are a bit convoluted. Lots of models with few differences, resulting in a lot of models submodules and classes. To make the clients more developer-friendly, I'm wrapping all their endpoints in one class each, flattening the arguments in each method.
A typical example:
As you can see I'm simplifying the name and usage:
...becomes:
I can then wrap multiple classes like that into a main one:
In the end, a developer can just import and instantiate the API class, and start using every possible endpoint, without importing any model or endpoint themselves:
Anyway! (just explaning my use case)
Describe the solution you'd like
I'm not asking you to change how to generate clients. Rather, I'd like to be able to "add" templates to the generation process, so I could automatically (re)generate these wrapper classes of mine, using
openapi-python-client
's Jinja context. Sorry for the long introduction 😅It could be done with a command line option to tell
openapi-python-client
to render every template within the specified folder into the generated client. The directory structure would be respected, allowing the user to "inject" new contents in any subfolder of the generated client.Describe alternatives you've considered
Improve the OpenAPI specs I'm using, but it would result in breaking changes, so a lot more work for many other people in my team and other teams 😮
Additional context
Maybe what I'm doing here is plain wrong and I'm losing benefits of the generated clients layouts? Don't hesitate to share on this matter 😄
The text was updated successfully, but these errors were encountered: