Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes incorrect Jackson imports in Java templates used in ApiClient.java when useJakartaEe=true #18507

Conversation

JochemKuijpers
Copy link
Contributor

@JochemKuijpers JochemKuijpers commented Apr 26, 2024

This PR aims to fix a compiler issue I ran into when generating java code from an API spec.

The generated code imports com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in ApiClient.java, which is the javax package, while my project uses jakarta and requires com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider. Upon searching, this seems to be a long-standing issue in this specific configuration, I was able to find at least one issue directly referencing it: #15875.

Upon digging deeper, it seems the generated ApiClient.java file in my particular configuration (using the apache-httpclient library) doesn't even use the imported class, so in this specialized template it can even be omitted, as is the case in a secondary issue reported as #18289.

The PR does not add any new template parameters, but instead switches over the useJakartaEe parameter already exposed to select the appropriate Jackson package to import. This should fix this problem for all Java templates. In addition, I have removed the unused import for the apache-httpclient specifically, since it is not needed.

Tagging committee members as requested in the checklist:
@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg

I can currently work around the compile issue in my project through an overwritten template file in my template folder where I've fixed this locally, but this PR should fix it for everyone else running into the same issue.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328
Copy link
Member

wing328 commented Apr 27, 2024

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

… to import.

This also removes the import on the apache-httpclient template where it doesn't actually get used, requiring users to declare additional dependencies for compilation that aren't actually required by the generated code other than for import.
@JochemKuijpers JochemKuijpers force-pushed the bugfix/java-jakarta-jackson-templates branch from 442ccf1 to c237671 Compare April 27, 2024 20:21
@JochemKuijpers
Copy link
Contributor Author

JochemKuijpers commented Apr 27, 2024

Thanks for the heads-up @wing328 -- incorrect git config on my part. Should be fixed now 🙂
Let me know if you need anything else to get this merged!

@JochemKuijpers
Copy link
Contributor Author

@wing328 sorry for the poke, but is there anything else that needs to be done or can this be merged?

@beikov
Copy link

beikov commented May 1, 2024

I need this too. Please merge and create a new release when possible.

@wing328 wing328 added this to the 7.6.0 milestone May 5, 2024
@wing328
Copy link
Member

wing328 commented May 12, 2024

@JochemKuijpers thanks for the PR. I'll run some tests and try to get it merged before the upcoming v7.6.0 release.

@wing328
Copy link
Member

wing328 commented May 13, 2024

tested locally and the output compiles (except jaxrs-cxf-extended, which has the same issue in the latest master anyway, we will look into it separately)

@wing328 wing328 merged commit 2f9b487 into OpenAPITools:master May 13, 2024
72 checks passed
@JochemKuijpers JochemKuijpers deleted the bugfix/java-jakarta-jackson-templates branch May 15, 2024 07:53
renatomameli pushed a commit to renatomameli/openapi-generator that referenced this pull request May 17, 2024
…ava when useJakartaEe=true (OpenAPITools#18507)

* Adds useJakartaEe condition to select the appropriate Jackson package to import.

This also removes the import on the apache-httpclient template where it doesn't actually get used, requiring users to declare additional dependencies for compilation that aren't actually required by the generated code other than for import.

* Ran generate-samples.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants