You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using the JAX-RS Spec generator you are able to ask the builder to create a builder for model that will be transferred. This was added in #4930. However, the way it was implemented means that the constructor of the object is repeated for each field in the model.
The issue here is that the same constructor is here twice, and it doesn't have any parameters. I believe this latter is because we're inside a loop and the nesting doesn't work. The result of this is that the generated java code does not compile:
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/MapTest.java:[86,10] constructor MapTest() is already defined in class org.openapitools.model.MapTest
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/MapTest.java:[105,10] constructor MapTest() is already defined in class org.openapitools.model.MapTest
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/MapTest.java:[124,10] constructor MapTest() is already defined in class org.openapitools.model.MapTest
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/Order.java:[86,10] constructor Order() is already defined in class org.openapitools.model.Order
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/Order.java:[105,10] constructor Order() is already defined in class org.openapitools.model.Order
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/Order.java:[124,10] constructor Order() is already defined in class org.openapitools.model.Order
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/Order.java:[144,10] constructor Order() is already defined in class org.openapitools.model.Order
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/Order.java:[163,10] constructor Order() is already defined in class org.openapitools.model.Order
[ERROR] /home/danielho/Projects/OpenSource/openapi-generator/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/Capitalization.java:[52,10] constructor Capitalization() is already defined in class org.openapitools.model.Capitalization
I believe the constructor generator only needs to be moved to get this to work. It's still not possible to generate builders for types with parents, but that was already the case in #4930.
openapi-generator version
I have tested this occours in the latest master branch, and on the last release version 4.3.1
OpenAPI declaration file content or url
This was generated from the petstore sample in the repostitory
Generation Details
Add the following to the jaxrs-spec-interface.yaml sample generation file:
generateBuilders: "true"
Steps to reproduce
Add generateBuilders: "true" to the jaxrs-spec-interface sample generation
Generate the samples.
Try to compile the petstore sample
This will fail as above
Related issues/PRs
This seems to have always been an issue since it was introduced in #4930
Using the 'generateBuilders' no longer generates multiple constructors,
but only one for each class. This still does not work with models that
use inheritance.
FixesOpenAPITools#8132
Bug Report Checklist
Description
When using the JAX-RS Spec generator you are able to ask the builder to create a builder for model that will be transferred. This was added in #4930. However, the way it was implemented means that the constructor of the object is repeated for each field in the model.
Essentially the template for the constructor (https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache#L37-L41) is inside the loop which is generating the variables. This results in java code like this:
The issue here is that the same constructor is here twice, and it doesn't have any parameters. I believe this latter is because we're inside a loop and the nesting doesn't work. The result of this is that the generated java code does not compile:
I believe the constructor generator only needs to be moved to get this to work. It's still not possible to generate builders for types with parents, but that was already the case in #4930.
openapi-generator version
I have tested this occours in the latest master branch, and on the last release version 4.3.1
OpenAPI declaration file content or url
This was generated from the petstore sample in the repostitory
Generation Details
Add the following to the
jaxrs-spec-interface.yaml
sample generation file:Steps to reproduce
generateBuilders: "true"
to the jaxrs-spec-interface sample generationThis will fail as above
Related issues/PRs
This seems to have always been an issue since it was introduced in #4930
Suggest a fix
I believe this can be fixed by moving the constructor generation further down the template, outside the
vars
loop. https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pojo.mustache#L37-L41. I will make a PR for this change.The text was updated successfully, but these errors were encountered: