I am using the OpenAPI Generator in a Gradle project to generate API client and model classes from an OpenAPI specification. We are upgrading our application to Spring Boot 3.x.x, which no longer supports javax annotations. However, the generated code still imports javax.annotation.Generated, even though I have set the jakarta configuration option to true in the generator settings.
Here’s the relevant section of my build.gradle file:
openApiGenerate {
inputSpec.set("$rootDir/src/main/resources/c-c.yml")
outputDir.set("$buildDir/generated/")
generatorName.set("spring")
modelPackage.set("com.a.b.c.model")
apiPackage.set("com.a.b.c.api")
invokerPackage.set("com.a.b.c.invoker")
generateApiTests.set(false)
generateModelTests.set(false)
configOptions = [
"library" : "spring-boot",
"dateLibrary" : "java8",
"reactive" : "true",
"interfaceOnly" : "true",
"openApiNullable": "false",
"useOptional" : "true",
"jakarta" : "true" // I have set this to true
]
}
Despite setting jakarta: true, the generated code still imports javax.annotation.Generated instead of jakarta.annotation.Generated.
Since we are upgrading to Spring Boot 3.x.x and javax annotations are no longer supported, is there a way to configure the OpenAPI Generator to generate code that uses jakarta.annotation.Generated instead?
Has anyone faced this issue or knows how to properly configure the OpenAPI Generator for this?
If we follow the docs, correct setting is useJakartaEe
. Tested and verified with this (Gradle Kotlin):
plugins {
java
id("org.springframework.boot") version "3.4.2"
id("io.spring.dependency-management") version "1.1.7"
id("org.openapi.generator") version "7.11.0"
}
openApiGenerate {
inputSpec.set("$rootDir/src/main/resources/c-c.yml")
generatorName.set("spring")
modelPackage.set("com.a.b.c.model")
apiPackage.set("com.a.b.c.api")
invokerPackage.set("com.a.b.c.invoker")
generateApiTests.set(false)
generateModelTests.set(false)
configOptions.set(mapOf(
"library" to "spring-boot",
"dateLibrary" to "java8",
"reactive" to "true",
"interfaceOnly" to "true",
"opemApiNullable" to "false",
"useOptional" to "true",
"useJakartaEe" to "true", // changed from jakarta
))
}