OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA][MICROPROFILE] Error during client generation due to wrong import addition
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Generating a client for language Java, library Microprofile, in a maven project, the compilation failed due to additional packages that are not included in microprofile dependencies. To be specific:
- Date library are always JodaTime, even if something different is specified
- javax.xml.bind are always imported, even if xml is set to false
- package org.apache.cxf.jaxrs.ext.multipart is always declared as import
Point 2 and 3 are packages that are not used in the code.
It's possible to fix these behavior, to avoid to have to add not necessary dependencies to the project?
openapi-generator version
openapi-generator 4.3.0 used
OpenAPI declaration file content or url
To try to make it work at least locally, this is what i found in the code:
-
JodaTime:
in modules\openapi-generator\src\main\java\org\openapitools\codegen\languages\JavaClientCodegen.java:- comment line 422 (importMapping.put("LocalDate", "org.joda.time.LocalDate");)
- comment line 202-203
} else if (MICROPROFILE.equals(getLibrary())) {
dateLibrary = "legacy";
to disable the forcing of JodaLibraries as api, and it works perfectly, for JAVA8. Not tested for other date approach
-
XML package import always present:
In modules\openapi-generator\src\main\resources\Java\libraries\microprofile\pojo.mustache i replaced
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;with
{{#withXml}}
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
{{/withXml}} -
For cxf multipart:
In modules\openapi-generator\src\main\resources\Java\libraries\microprofile\api.mustache removed
{{^disableMultipart}}
import org.apache.cxf.jaxrs.ext.multipart.*;
{{/disableMultipart}}
In this case, to make it works i can only remove these three lines; also this disableMultiPart is not clear from where it came from.
Command line used for generation
Maven project, mvn compile generate the error
Steps to reproduce
Execute a mvn compile on the sample projects sample.zip
Related issues/PRs
I haven't found any related issues/PRs
Suggest a fix/enhancement
fix/enhancement described previously
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in JavaClientCodegen.java and the MicroProfile templates pojo.mustache and api.mustache, reviewing date-library selection and the withXml and disableMultipart conditions. Run mvn compile on the provided sample project and verify generated clients compile without unnecessary JodaTime, JAXB, or CXF multipart dependencies.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100