Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7209
Closed
Open
Issue created Aug 13, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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
  1. Generate client sources for any valid v3 yaml, using generator 'java' and library 'resttemplate' and configOption withXml enabled.
  2. Open the generated ApiClient.java and search for JsonNullableModule, you'll notice that it is used without an import statement.
  3. Compiling the generated sources will result with a "cannot find symbol" error message.
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking