-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Data object classes for templating context #837
base: master
Are you sure you want to change the base?
Data object classes for templating context #837
Conversation
I'll try to review this later this weekend. At first glance, I notice that you're passing "bundle" templating objects around the workflow. That might tie templating too tightly to the workflow (which I feel would be better as procedurally input > transform > templating). I like the idea of getting rid of |
I agree, for now these are in org.openapitools.codegen.templating, a better home might be org.openapitools.codegen.models or something like that. The jackson conversion for Bundle->Map is failing hard, because there is cycle in the model (CodegenModel has a children list and these contain a parent field), I need to do it differently :-) |
I've created a Separation of Concerns project to track some of the larger refactoring efforts. I've added this PR and #690 to that project, because I think they're both directly related to the efforts I've documented in the project. As I discussed in #690, If we change all input parameters to these Edit: It's considered a major breaking change because a use case for the generator is for consumers to create and artifact with opeanpi-generator as a dependency, and extend |
da2ee24
to
391527e
Compare
a1dec8c
to
4a29d4d
Compare
Thanks @jimschubert. I've gone back and put backward compatibility in place again, not modifying the public interfaces and methods. Methods using the Map<String, Object> are deprecated: The code needs a good squashing, sorry about that :-) |
@rienafairefr sorry I've just seen your response. I've had a lot of stuff come up lately (I'm building a house and will be moving in about 6 weeks). I'll try to get this reviewed over the next week. |
f3c9d92
to
38c66d0
Compare
@jimschubert I've rewritten and removed the changes in public interface altogether, the generators still operate on |
@rienafairefr awesome. I'll try to take a look this week. Is there anything you'd like me to try and tackle? |
9b9d054
to
6b400e8
Compare
6b400e8
to
01284e6
Compare
Sorry in advance for the massive PR, though I can't seem to see how it could be made with less
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,3.3.x
,4.0.x
. Default:master
.@jimschubert @wing328
Description of the PR
in some discussion with @jimschubert here I've seen that the current plethora of Map<String, Object> pseudo-classes should be avoided. Indeed, it's making us do a lot of casting back and forth between Object and Map<String, Object>, a lot of unchecked casting warnings are suppressed, type safety is not used, overall it's something that could be changed for the better
I've implemented a bunch of data-only classes (suffixed
Bundle
s for now but I could see usingDTO
orBag
if whatever terminology is preferred) for replacing all these Map<String, Object> that could be replaced. Of course we need to keep the vendorExtensions, additionalProperties maps, and probably others I'm forgetting of the top of my head, unchanged, because these really need to be truly dynamic (they can be changed by the spec or the user).There is a bit of conundrum with the additionalProperties there because when executing a template, we want to pass it a context that can be a POJO, but we also want the values from additionalProperties to be available (e.g.
{{licenseInfo}}
or{{appDescription}}
. I added a AdditionalPropertiesBundle base class to handle that, but it feels hacky to me: I convert the POJO to a map, and add the additionalproperties to it, just before it goes into thetemplate.execute(context...)
, it needs a better solution I think.