I've recently upgraded my project to use spring-boot 3.0.0. So I don't have javax.*
modules in the project anymore. But the Open API generator keeps trying to import javax
modules. Especially, it uses javax.annotation.Generated
for the @Generated
annotation which is not present in the project anymore. Is there a way to reconfigure it somehow?
-
The generator documentation page (https://openapi-generator.tech/docs/generators) is always the first goto in these cases. OpenAPI tech is well adapted and chances are, the community has already hit the issue and delivered the fix – Ashwin Prabhu Mar 27 '23 at 11:09
-
can you share where they fixed the issues ? – SANJAY GAUTAM Jul 13 '23 at 01:25
-
2@SANJAYGAUTAM see sashok_bg's answer https://stackoverflow.com/a/75743432/2886891 - it works with `
true
4 Answers
Yes, you can use useSpringBoot3: "true" in your configoptions of the generator. Example in gradle:
configOptions = [
useSpringBoot3: "true"
]

- 289
- 1
- 2
-
For some weird reason, this option works only for the SPRING generator https://openapi-generator.tech/docs/generators/spring/, which generates the server. – Honza Zidek Nov 28 '22 at 16:48
-
1
-
3The top option only works for the `Spring` generator. If you are generating code for the client like `Java` generator, this option is not available. Currently I don't see any option to allow Jakarta migration. – Amrut Prabhu Dec 10 '22 at 12:31
-
1Its still an open issue : https://github.com/OpenAPITools/openapi-generator/issues/13124 – Amrut Prabhu Dec 10 '22 at 12:51
-
8It seems that setting `useJakartaEe: 'true'` should work in the `java` generator since openapi-generator 6.3.0, but apparently some configurations are not working well, and thus the issue is still open. It works well for me using the `native` library! – skagedal Mar 05 '23 at 13:16
You should follow the documentation whenever possible.
The property that you need is either "useSpringBoot3" or "useJakartaEe"
Go to https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin
At the end of the table you see "configHelp" property which will give you configs for the current generator "spring" in my case
Rerun "mvn clean install" - this will give you a list of available "configOptions".
Read the list and found a property
useJakartaEe: whether to use Jakarta EE namespace instead of javax (Default: false)
My final pom:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<configHelp>false</configHelp>
<configOptions>
<useJakartaEe>true</useJakartaEe>
</configOptions>
<inputSpec>
${project.basedir}/src/main/resources/api.openapi.yaml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>some.package</apiPackage>
<modelPackage>some.package.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
Cheers

- 2,436
- 1
- 22
- 33
-
using the setting ```
true ``` gives me the error ```package jakarta.annotation does not exist```. What am I doing wrong? Here is the pom snippet: https://pastebin.com/KGvwFauv – Arthur Eirich Aug 02 '23 at 10:43 -
@ArthurEirich do you have the correct Jakarta dependency versions? I had a similar error, it turned out I forgot to include jakarta.annotation-api in a version which actually uses the new jakarta.annotation package name – Don Ho Aug 15 '23 at 13:42
-
I had all the needed dependencies. My problem was the option `
false ` not being set. After I scrolled trhough the log I saw a warning that a model class wasnt generated. Googled the log message for it and found a github bug – Arthur Eirich Aug 16 '23 at 06:42 -
@DonHo https://github.com/OpenAPITools/openapi-generator/issues/10415 and https://github.com/OpenAPITools/openapi-generator/issues/12036 are those bugs where I found out about the option – Arthur Eirich Aug 16 '23 at 06:46
I used the following as well, in my config.json file:
configOptions = [
useSpringBoot3: "true"
]
I heard other places that it should be default on newer versions of openapi generator - but in my case it was not and I had to force it this way which worked.

- 29
- 2
-
I can now confirm as well, that I am not able to replace the javax with jakarta in all my generated files. I've looked around so far with no luck. – MegaMoth Jan 04 '23 at 08:10
-
You just plagiarized @Shaki's answer which is about a month older. Before posting, you should first read other answers. Your post has ZERO value. – Honza Zidek Jul 13 '23 at 09:24
-
I literally only wanted to help confirm a hypothesis. This is the most demotivating reply I've had. – MegaMoth Jul 14 '23 at 17:23
-
OK, for this purpose StackOverlow has comments. Just add a comment to the answer you want to confirm. Please read https://stackoverflow.com/tour and https://stackoverflow.com/help/deleted-answers - namely "Answer posts that do not fundamentally answer the question may be removed. This includes answers that are: ... exact duplicates of other answers." – Honza Zidek Jul 14 '23 at 18:45
I use openapi-generator generate
command and adding options that
--additional-properties=useSpringBoot3=true
also worked. Here is the reference: https://openapi-generator.tech/docs/generators/spring/

- 1
- 1