[JAVA] Generate and use variable name for setting discriminator and fix #9205 #9207
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR checklist
3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Doesn't seem to be a name on the technical committee for Java.
The original change was made by @SergeyLyakhov and the person who authorized it @wing328
Description of the PR
This fixes a bug with discriminators that are specified with underscores.
In v2.4.0 a change was made which automatically populated the discriminator variable
with the class name. However whilst the variable name was converted from the model to
a java friendly variable, for example object_type to objectType in the parent class
the set variable didn't translate accordingly and so leaves uncompilable code.
As a result the generated code produced was...
and not
I created new discriminatorClassVarName variable in the CodegenModel to store the converted discriminator name and populated it with the discriminator value converted to the correct style by calling the existing toParamName method.
I'm happy to refactor that code before merging in as the nested ifs are getting a bit nasty but didn't want to do that until someone had signed off on the approach as I don't know the code base and might be missing a better solution.
Also change the pojo mustache template to use the new variable rather than the plain discriminator value currently used.
If the PR is missing info you need apologies it's my first.