[BUG] Missing import statement in ApiClient.java for JsonNullableModule when using generator 'java' and library 'resttemplate' with option 'withXml' enabled
Created by: anthonyhseb
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
When adding the withXml : "true"
option in order for the java
generator (with the 'resttemplate' library) to include @XmlRootElement
, @JacksonXmlRootElement
annotations necessary to name the root element in the XML request body, the generated ApiClient.java
class fails to compile giving the following error.
ApiClient.java:648: error: cannot find symbol
xmlMapper.registerModule(new JsonNullableModule());
^
symbol: class JsonNullableModule
location: class ApiClient
Looking at the imported classes in ApiClient.java
, there is no import statement for that class, and it has to be added manually whenever the client code is regenerated.
Without withXml : "true"
the generated source does compile but the class name is used for root elements instead of the declared name
in the spec.
Using the Gradle plugin with the following config:
task myGenerateTask (type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName = "java"
library = "resttemplate"
inputSpec = project.projectDir.getPath() + "/src/main/schema/myservice.yaml"
outputDir = project.buildDir.getPath() + "/generated-sources/myservice"
generateModelTests = false
generateModelDocumentation = false
generateApiTests = false
generateApiDocumentation = false
def rootPackage = "mypackage"
apiPackage = rootPackage + ".api"
invokerPackage = rootPackage + ".client"
modelPackage = rootPackage + ".model"
configOptions = [
java8 : "true",
dateLibrary: "java8",
withXml : "true"
]
inputs.file inputSpec
outputs.dir outputDir
}
openapi-generator version
Tested with 4.3.0, 4.3.1, and 5.0.0-beta
OpenAPI declaration file content or url
I cannot share the spec file since it is confidential, the file passes validation, and is fairly standard.
The file contains type declarations, with an xml
name
property.
MyType:
properties:
code:
type: integer
description: Identifier.
label:
type: string
description: A human-readable label.
example:
code: 100
label: Foo
xml:
name: myObject
Generation Details
Using Gradle with org.openapitools:openapi-generator-gradle-plugin:4.3.1
(or any of the versions mentioned above)
gradle myGenerateTask
Then compile the generated sources.
Steps to reproduce
- Generate client sources for any valid v3 yaml, using generator 'java' and library 'resttemplate' and
configOption
withXml
enabled. - Open the generated
ApiClient.java
and search forJsonNullableModule
, you'll notice that it is used without animport
statement. - Compiling the generated sources will result with a "cannot find symbol" error message.