-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[REQ] [Java] Support of JakartaEE 9 #13124
Comments
This has been a request for two years now: |
This is a big problem now that Spring Boot 3.x / Spring Framework 6.x are released and only support Java 17 + JakartaEE 9. OpenApi generator no longer will work with any up-to-date spring apps. |
Wasn't this feature already implemented in: #12407 ? |
i suppose it's not clear, from the ticket - but i believe server side support has been implemented, but client generation still does not support emitting JakartaEE 9 annotations (Generated, bean validation, etc.) |
This is a huge blocker for migration to spring boot 3. |
This is a blocker for us as well. As an option would be the usage of spring generator, but it generates Java classes which is not the aim. |
Is there a work around here? |
As a workaround, you can do the following: <plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.2.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/api.yml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.api</apiPackage>
<modelPackage>com.api.model</modelPackage>
<generateApiTests>false</generateApiTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<performBeanValidation>true</performBeanValidation>
<useBeanValidation>true</useBeanValidation>
<serializationLibrary>jackson</serializationLibrary>
<delegatePattern>false</delegatePattern>
<skipDefaultInterface>true</skipDefaultInterface>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<!-- com.google.code.maven-replacer-plugin - Workaround : waiting for openapi-generator-maven-plugin supports jakartaEE 9. -->
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>replace-import-javax-by-jakarta</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>
${project.build.directory}/generated-sources/openapi/src/main/java/com/api
</basedir>
<includes>
<include>**/*.java</include>
</includes>
<replacements>
<replacement>
<token>import javax</token>
<value>import jakarta</value>
</replacement>
</replacements>
</configuration>
</plugin> The plugin com.google.code.maven-replacer-plugin:replacer search "import javax" strings in the generated files and replace them with "import jakarta" strings. |
anyone happen to know of a similar plugin for gradle, google isn't giving me much luck |
For me the "spring" generator (6.2.1) worked with |
I can confirm the "spring" generator solution, but couldn't make it work for the "java" generator (we use |
For me |
That's strange, we use |
Another update: it works for me with just a client and Spring Boot 3. Here's the Maven config: <plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.3.0-SNAPSHOT</version>
<executions>
<execution>
<id>openapi-client</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatorName>java</generatorName>
<apiPackage>com.example.demo.client</apiPackage>
<modelPackage>com.example.demo.client</modelPackage>
<invokerPackage>com.example.demo.client</invokerPackage>
<configOptions>
<useJakartaEe>true</useJakartaEe>
<library>webclient</library>
</configOptions>
</configuration>
</execution>
</executions>
<configuration>
<inputSpec>${project.basedir}/openapi.yaml</inputSpec>
<configOptions>
<performBeanValidation>true</performBeanValidation>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<useBeanValidation>true</useBeanValidation>
<sourceFolder>src/main/java</sourceFolder>
<configPackage>com.example.demo.config</configPackage>
</configOptions>
</configuration>
</plugin> |
Thanks to you guys for trying to figure out workarounds for this serious unexpected blocker on moving to SpringBoot 3. Do I need to use the snapshot version of the plugin? I am trying with 6.2.1 without messing with our build setup. Trying to add to my existing execution config: I had the other options but didn't have With or without the latter / useSpringBoot3 I am getting:
|
I'm not sure what the "html" generator does with a "library" (it's not documented). Did it ever work? Anyway the examples above are all for the "spring" and "java" generators. |
After the spring-mvc error it actually said that the spring-boot library was available...so I updated spring-mvc to spring-boot and it passed that error and generated the 58 resources!! But the generated file contains Thanks for letting me know about generatorName. We have always generated java even with that set to html! I tried replacing it with both spring and java and neither result in javax being removed. Prior to build failure there is an info message, should I bother with it? Testing to see if I get it working with 6.3.0-SNAPSHOT I played with my active profile in settings.xml & updating snapshotRepository in my pom.xml but nothing worked out to download 6.3.0-SNAPSHOT. any advice is appreciated... |
My sample is here if you want to crib the pom.xml config: https://github.com/dsyer/openapi-demo. If you share your minimal sample I might be able to see what you need. UPDATE: there's a "client" branch that does "webclient" only (no server). |
Thank you!! I see you use 6.3.0-SNAPSHOT, so that definitely needed then over 6.2.1? What did you add in your settings.xml to allow that to download? I tried your config, I was not using the outer for spring and I moved to use the resttemplate library. My generated file does not import javax! But it does use @javax.annotation.Generated, is that wrong? The build subsequently failed as [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.3.0:resources (default-resources) on project ABC: filtering ...\src\main\resources\v1\gradle\wrapper\gradle-wrapper.jar to ...\target\classes\v1\gradle\wrapper\gradle-wrapper.jar failed with MalformedInputException: Input length = 1 Not sure yet if this related to the plugin. |
There's nothing in my settings.xml (AFAIK) it's all in the pom. If you read the comments above you will find that snapshots are only needed for the "java" generator. If you are getting The thing with the gradle wrapper is weird (why is it in your classpath resources?), but looks completely unrelated to OpenAPI code generation. |
The Gradle wrapper is not generated by a maven plugin. Is your project a maven or gradle project? It seems like maven, and if so, you almost certainly want to update your Also then share the entirety of your |
We do not use gradle at all, it's a java project! I checked and previously the Gradle stuff was not generated! Something must have changed in the current plugin I guess and I need a new config setting? But you say it's not generated by the generator... what else would create the folder \target\generated-sources\openapi\gradle ? ... will play with .openapi-generator-ignore but think it should not be generated if the settings are correct as @dsyer didn't use openapi-generator-ignore in his demo code Full config UPDATED 27 Feb 23:
Is there anything in these settings that pulls gradle into the generation? |
Sort of. You are using the |
Thanks for the reply. The way you say "I am using the openapi-generator-maven-plugin" suggests there may be another one? This pom snippet worked with 5.0.0 previously in our code for years. My only goal here is to have it working with Spring Boot 3, not change any functionality. The solution with 5.0.0 did not generate Gradle (I have double-checked), so it looks like that was added in v6 to be done by default? That said 2 weeks ago @madorb was looking for a similar plugin for gradle even though this does one does gradle, so I am quiet confused. How do others stop Gradle from being generated by default? |
I suspect they don't bother mostly. It hasn't been an issue for me - I just ignore some of the generated files. |
Fair enough. I don't care about Gradle being generated if it was not causing me an issue. |
I don't see mention of Support for JakartaEE 9 in the release notes of 6.3, which was released? |
the release note only highlights some changes but not all. please refer to https://github.com/OpenAPITools/openapi-generator/pulls?q=is%3Apr+is%3Amerged+milestone%3A6.3.0 for a full list of changes. i'm still revising the release note. |
@wing328 thanks for letting me know. |
can you share more details on how you generate the code? e.g. spec, generator name, options, etc |
I can confirm that with this config and 6.3.0, I'm getting jakarta annotations openApiGenerate {
generatorName = "java"
inputSpec = "$buildDir/openapi.yaml"
outputDir = projectDir.path
packageName = "foo"
apiPackage = "foo"
modelPackage = "foo"
ignoreFileOverride = "$projectDir/.openapi-generator-ignore"
configOptions = [
apiPackage: "foo",
modelPackage: "foo",
asyncNative: "true",
documentationProvider: "none",
library: "resteasy",
microprofileRestClientVersion: "3.0",
useJakartaEe: "true"
]
} |
Thanks for reply. My pom settings are above |
Can I suggest we close this issue and invite people to raise separate requests about specific combinations that do not currently work? Or maybe we could document which combinations actually do work a bit better somewhere. E.g. a table in the form
(*)Default for this generator. Generates a server. |
Like this one from 2020? 😢 Already mentioned it a few times. |
Library is an optional configuration setting. I'd be happy to add other generators if you tell me you have tested it and it works. |
That would be My apps will always only use the API (dependency scope=provided in maven) and the implementation only in the runtime. So yes, it is already heavily used. Some IBMers working on Open Liberty did comment in the issue I mentioned, too. |
I didn't see any actual solutions proposed in that other issue, but I'm happy to take your word for it if you say it works. I just don't know what, precisely, you are saying works already. I don't see any references to a generator called "restfulWs", and there is a "useJakartaEe" flag for "jaxrs-spec" but does it work, and is it needed? Has anyone actually tested the other "jaxrs-*" generators? |
I have been looking at this again and using 6.4.0, trying to get unblocked. I have made some progress. @dsyer's example client does not UseSpringBoot3 and my config was not using useJakartaEe in the java generator, I had it in the 2nd spring generator. When it recompiles I now get errors:
Some of these dependencies are in a new file /target/pom.xml, separate from target/generated-sources/pom.xml., but not all of them, e,g. okio is not. I have my code working with v5.0.0 of the plugin for v2.7.5 of Spring Boot and there was no target/pom.xml generated. This error is reported at #14270 with an example project Others here have all working for useSpringBoot3 I believe. |
It would really be better to post this as a question on stackoverflow and/or provide a full working sample. Which of the matrix combinations in my table above are you using? |
I'm upgrading to spring boot v3 so the combination is 2 rows in your matrix: I'm unsure why here is not suitable since people are trying to get workarounds for functionality which has not been implemented yet in the plugin. |
The way I read it, the config in that link has two executions with |
Thanks for sticking with me. I know if you didn't; no one would as this is just one of 2000+ bugs multiple pages down the list that no one ever visits unless they encounter this problem. I will try and see if I can create a sscce, you will be the only one looking at it I think. The sscce for the 14270 bug, which I am now getting was never commented on by anyone. Apologies, the config is updated now. I had moved useJakartaEe to the first execution. But are you saying, Java, useSpringBoot3, useJakartaEe is not valid? But Spring Boot 3 uses Jakarta, that's the nub of the whole thing,
|
Here's what I see in that fragment:
So the "server" execution generates a client, and it doesn't use a library so there won't be any Spring. And the "client" generates a server, and there is no |
Many thanks for sticking with me. I guess I was confused too. With the
This is what I want to reproduce with the new version. So your comment got me to wonder maybe I only need the client ....testing combinations of the matrix... |
It's hard to say. Your reluctance to provide a sample is a problem. I could hazard a guess that since you generate |
Came here from this Stack Overflow-comment and just wanted to say that |
The feign generator still creates a build.gradle (and build.sbt) with the wrong jakarta version (with javax package), the generated pom.xml is correct. |
I wonder if you can file a PR to fix it 🙏 |
The build.gradle for the resttemplate generator also seems wrong when useJakartaEe is true. It lists a dependency on com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider instead of com.fasterxml.jackson.jakarta.rs:jackson-jakarta-rs-json-provider. The pom.xml file seems to have the correct jakarta dependency. |
@douggish may I know if you can help contribute a PR to fix it? a good starting point is to compare the following:
|
I would have to ask for permission from my company. What is the process for contributing? Is there a Contributor License Agreement that would need to be signed, etc.? |
No need to sign CLA https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-submit-a-pr-to-fix-bugs-or-make-enhancements is a good starting point. |
Alright, I created a PR: #20322 |
PR merged. Thanks for the contribution. |
Context
Since Eclipse Foundation is in charge of JakartaEE specifications, it's time to switch to JakartaEE 9 for openapi generator.
The first step was to switch to JakartaEE 8 (see the issue #10504). It's done now.
The next step is to upgrade to JakartaEE 9 which means to upgrade to new versions of jakarta's dependencies.
But this upgrade is a bit more difficult than the previous because the main goal of JakartaEE 9 is that the javax.* packages to jakarta.* packages have been renamed by Eclipse.
I think that it will be necessary to create a new property (named jakartaeeVersion=9 for example) to allow the user to generate the source code with the actual versions of jakartaEE 8 or the last versions of jakartaEE 9.
Describe the solution you'd like
We need to upgrade the following dependencies in the Maven/Gradle/Scala mustache template files. These template files are located in openapi-generator/modules/openapi-generator/src/main/resources.
jakarta.annotation:jakarta.annotation-api:1.3.5 => 2.0.0
jakarta.validation:jakarta.validation-api:2.0.2 => 3.0.0
jakarta.ws.rs:jakarta.ws.rs-api:2.1.6 => 3.0.0
jakarta.json.bind:jakarta.json.bind-api:1.0.2 => 2.0.0
jakarta.json:jakarta.json-api:1.1.6 => 2.0.0
jakarta.xml.bind:jakarta.xml.bind-api:2.3.3 => 3.0.0
jakarta.el:jakarta.el-api:3.0.3 => 4.0.0
jakarta.servlet:jakarta.servlet-api:4.0.4 => 5.0.0
jakarta.activation:jakarta.activation-api:1.2.2 => 2.0.0
The upgrade of jakarta versions will force us to replace all javax.* import by jakarta.* in the mustache templates.
Then, we need a new property named jakartaeeVersion to keep the generation source code as is (with the package javax.* ) or to use the new jakartaEE 9 classes in the generated source code.
By default, if the property didn't set, we consider that we are still on jakartaEE 8 (javax.*).
Beware, some samples are dependents of Spring Boot. For them, it will be necessary to upgrade the version of spring boot parent to 3 (release in September 2022). It is not part of the scope of this issue.
How to validate the request
We need to create an unit test with the property jakartaeeVersion. The versions of depedencies should be equal to the versions above.
And of course, we need to create a new java sample with the new property.
Additional context
Versions of JakartaEE 9 : https://projects.eclipse.org/releases/jakarta-ee-9. Or a map here https://jakarta.ee/release/9/
Explanations of JakartaEE 9 release plan : https://eclipse-ee4j.github.io/jakartaee-platform/jakartaee9/JakartaEE9ReleasePlan
The text was updated successfully, but these errors were encountered: