swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.96k stars 6.04k forks source link

[JAVA][maven-plugin]When used with Jersey2 and withXml true, required jackson-dataformat-xml dependency is missing in pom #10895

Open Abhishek-P opened 3 years ago

Abhishek-P commented 3 years ago
Description

When the maven plugin is used to generate the client classes with jersey2 as the library and withXml option as true. The following import is done in model

import com.fasterxml.jackson.dataformat.xml.annotation.*;

for using @JacksonXmlProperty(localName = "id")

But the dependency is missing in the pom.xml and the build.gradle files generated Only jaxb dependency gets added into the pom Not sure if it should be in the build.gradle also

I can see the corresponding mustache that the jacksin-dataformat is missing https://github.com/swagger-api/swagger-codegen/blob/068b1ebcb7b04a48ad38f1cadd24bb3810c9f1ab/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache#L251

I don't see withXML conditional in the gradle mustace - https://github.com/swagger-api/swagger-codegen/blob/068b1ebcb7b04a48ad38f1cadd24bb3810c9f1ab/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/build.gradle.mustache

Swagger-codegen version

2.3.1 Not sure if it is a regression

Swagger declaration file content or url

Not able to provide

Command line used for generation

Java codegen from swagger.json input through maven plugin XXX for used for some obfuscation for confidentiality `

${project.basedir}/target/swagger/swagger.json
          <output>target/swagger/client</output>
          <language>java</language>
          <configOptions>
            <apiPackage>XXX</apiPackage>
            <modelPackage>XXX</modelPackage>
            <invokerPackage>XXX</invokerPackage>
            <generateApiDocs>false</generateApiDocs>
            <generateModelDocs>false</generateModelDocs>
            <generateApiTests>false</generateApiTests>
            <generateModelTests>false</generateModelTests>
            <dateLibrary>java8</dateLibrary>
            <library>jersey2</library>
            <withXml>true</withXml>
          </configOptions>
        </configuration>`
Steps to reproduce

Use codege maven plugin to generate a client for Java with library jersey2 and withXml enabled as shown above

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/pull/5962

Suggest a fix/enhancement

Change the mustache files to include the required libraries

Abhishek-P commented 3 years ago

I was able to workaround by adding a customizing build.gradle.mustache with following edit Have to see if I need to change pom.xml also for the usage part post build.

{{#withXml}}
    compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jackson_version"
{{/withXml}}