Open asjp1970 opened 3 months ago
{{^-last}}, {{/-last}}
is the standard way of mustache.
You can adapt your pojo.mustache by looking at the default java of spring templates
Thanks @jpfinne , that solved the issue. But I still think there is a bug in the Java template engine, since it is something that worked before and does not seem to be deprecated.
Bug Report Checklist
Description
I came from version 4.0.2 of
openapi-generator-maven-plugin
and uplifted it to version 7.6.0. We are using our own templates to produce only the pojo's of our model. In our templatepojo.mustache
we need to generate equals and hash methods, so we need to iterate over {{vars}} until the last one to stop adding "&&" for the AND operation in equals method, or "," for adding object's attributes to the hash method.Here is the complete pojo.template in github.
In 4.4.2 this was working perfectly and this was the expected result (for the hash):
But, when we use version 7.6.0, this is the generated code, which, of course breaks the compilation because symbol
typetitleauthorspages
does not exist:As you can see, as
hasMore
is, for some reason, left undefined, the "," separating each one of the object's fields is not added and all attributes names are concanetated.Here is a minimal version of the project in github just to showcase and reproduce the problem with the minimum setup: https://github.com/asjp1970/openapi
openapi-generator version
7.6.0
But we have tried with previous versions between 4.0.2 and 7.6.0 with the same result. Something must have happened with the code generator when processing the variables of the templates.
OpenAPI declaration file content or url
Here is the api_sample.yaml in github.
Generation Details
Recreating the problem using the project in github is quite simple, no need to use CLI. The versions in github is ready to reproduce the problem.
Steps to reproduce
target/generated-sources/openapi/src/main/java/com/softvarivm/openapi/model/Book
to see the compilation failure:pom.xml
and replace 7.6.0 with 4.0.2 to see that everything worked like a charm.Related issues/PRs
No similar issues fouund.
Suggest a fix