diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java index bf36a0d80d..e04b9edf5e 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java @@ -512,6 +512,12 @@ public void processOpts() { } writePropertyBack(OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG, generateOperationOnlyForFirstTag); + if (additionalProperties.containsKey(USE_JAKARTA_EE)) { + setUseJakartaEe(convertPropertyToBoolean(USE_JAKARTA_EE)); + } + writePropertyBack(USE_JAKARTA_EE, useJakartaEe); + writePropertyBack(JAVAX_PACKAGE, useJakartaEe ? "jakarta" : "javax"); + maybeSetTestTool(); writePropertyBack(OPT_TEST, testTool); if (testTool.equals(OPT_TEST_JUNIT)) { @@ -540,9 +546,6 @@ public void processOpts() { supportingFiles.add(new SupportingFile("common/configuration/application.yml.mustache", resourceFolder, "application.yml").doNotOverwrite()); supportingFiles.add(new SupportingFile("common/configuration/logback.xml.mustache", resourceFolder, "logback.xml").doNotOverwrite()); - // Use jakarta instead of javax - additionalProperties.put("javaxPackage", "jakarta"); - // Use the default java time switch (dateLibrary) { case OPT_DATE_LIBRARY_OFFSET_DATETIME -> { diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java index e80d1a0f53..618ed5076c 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautKotlinCodegen.java @@ -223,6 +223,7 @@ protected AbstractMicronautKotlinCodegen() { // CHECKSTYLE:OFF // Set all the fields + useJakartaEe = true; useBeanValidation = true; visitable = false; hideGenerationTimestamp = false; @@ -580,6 +581,12 @@ public void processOpts() { } writePropertyBack(OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG, generateOperationOnlyForFirstTag); + if (additionalProperties.containsKey(USE_JAKARTA_EE)) { + setUseJakartaEe(convertPropertyToBoolean(USE_JAKARTA_EE)); + } + writePropertyBack(USE_JAKARTA_EE, useJakartaEe); + writePropertyBack(JAVAX_PACKAGE, useJakartaEe ? "jakarta" : "javax"); + maybeSetTestTool(); writePropertyBack(OPT_TEST, testTool); if (testTool.equals(OPT_TEST_JUNIT)) { @@ -606,9 +613,6 @@ public void processOpts() { supportingFiles.add(new SupportingFile("common/configuration/application.yml.mustache", resourcesFolder, "application.yml").doNotOverwrite()); supportingFiles.add(new SupportingFile("common/configuration/logback.xml.mustache", resourcesFolder, "logback.xml").doNotOverwrite()); - // Use jakarta instead of javax - additionalProperties.put("javaxPackage", "jakarta"); - // Use the default java time switch (dateLibrary) { case OPT_DATE_LIBRARY_OFFSET_DATETIME -> { diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorEntryPoint.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorEntryPoint.java index 20189cf73a..4364accd8e 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorEntryPoint.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorEntryPoint.java @@ -201,6 +201,7 @@ private void configureOptions() { javaCodeGen.setAdditionalOneOfTypeAnnotations(options.additionalOneOfTypeAnnotations); } + javaCodeGen.setUseJakartaEe(options.useJakartaEe); javaCodeGen.setUseOneOfInterfaces(options.useOneOfInterfaces); javaCodeGen.setReactive(options.reactive); javaCodeGen.setGenerateHttpResponseAlways(options.generateHttpResponseAlways); @@ -282,6 +283,7 @@ private void configureOptions() { kotlinCodeGen.setAdditionalOneOfTypeAnnotations(options.additionalOneOfTypeAnnotations); } + kotlinCodeGen.setUseJakartaEe(options.useJakartaEe); kotlinCodeGen.setUseOneOfInterfaces(options.useOneOfInterfaces); kotlinCodeGen.setReactive(options.reactive); kotlinCodeGen.setGenerateHttpResponseAlways(options.generateHttpResponseAlways); @@ -530,6 +532,7 @@ private static class DefaultOptionsBuilder implements MicronautCodeGeneratorOpti private String apiPackage; private String artifactId; + private boolean useJakartaEe = true; private boolean beanValidation = true; private boolean useEnumCaseInsensitive; private String invokerPackage; @@ -791,6 +794,12 @@ public MicronautCodeGeneratorOptionsBuilder withAdditionalProperties(Map parameterMappings, List responseBodyMappings, Map schemaMapping, diff --git a/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorOptionsBuilder.java b/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorOptionsBuilder.java index c21083a608..dc369971b4 100644 --- a/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorOptionsBuilder.java +++ b/openapi-generator/src/main/java/io/micronaut/openapi/generator/MicronautCodeGeneratorOptionsBuilder.java @@ -325,6 +325,15 @@ public interface MicronautCodeGeneratorOptionsBuilder { */ MicronautCodeGeneratorOptionsBuilder withAdditionalProperties(Map additionalProperties); + /** + * Flag to indicate whether to use the "jakarta" or "javax" package. + * + * @param useJakartaEe if true, then use the "jakarta" package, otherwise - "javax". + * + * @return this builder + */ + MicronautCodeGeneratorOptionsBuilder withUseJakartaEe(boolean useJakartaEe); + /** * The possible date-time formatting configurations. */ diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/client/auth/AuthorizationBinder.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/client/auth/AuthorizationBinder.mustache index f7bae38a86..1cac872f92 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/client/auth/AuthorizationBinder.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/client/auth/AuthorizationBinder.mustache @@ -10,7 +10,7 @@ import io.micronaut.core.util.StringUtils; import io.micronaut.http.MutableHttpRequest; import io.micronaut.http.client.bind.AnnotatedClientRequestBinder; import io.micronaut.http.client.bind.ClientRequestUriContext; -import jakarta.inject.Singleton; +import {{javaxPackage}}.inject.Singleton; import java.util.ArrayList; import java.util.List; {{#generatedAnnotation}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/client/test/api_test.groovy.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/client/test/api_test.groovy.mustache index b1ff42e96d..2014c0fbf9 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/client/test/api_test.groovy.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/client/test/api_test.groovy.mustache @@ -4,7 +4,7 @@ package {{package}} {{/imports}} import io.micronaut.test.extensions.spock.annotation.MicronautTest import spock.lang.Specification -import jakarta.inject.Inject +import {{javaxPackage}}.inject.Inject import spock.lang.Ignore {{#wrapInHttpResponse}} import io.micronaut.http.HttpResponse diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/client/test/api_test.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/client/test/api_test.mustache index 2ab1a9f787..586ab3769f 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/client/test/api_test.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/client/test/api_test.mustache @@ -6,7 +6,7 @@ import io.micronaut.test.extensions.junit5.annotation.MicronautTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; -import jakarta.inject.Inject; +import {{javaxPackage}}.inject.Inject; {{#wrapInHttpResponse}} import io.micronaut.http.HttpResponse; {{/wrapInHttpResponse}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/test/model_test.groovy.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/test/model_test.groovy.mustache index f45e6c11e9..a050de9b81 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/test/model_test.groovy.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/test/model_test.groovy.mustache @@ -4,7 +4,7 @@ package {{package}} {{/imports}} import io.micronaut.test.extensions.spock.annotation.MicronautTest import spock.lang.Specification -import jakarta.inject.Inject +import {{javaxPackage}}.inject.Inject /** * Model tests for {{classname}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/server/test/controller_test.groovy.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/server/test/controller_test.groovy.mustache index d8a72f960f..a019363fe2 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/server/test/controller_test.groovy.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/server/test/controller_test.groovy.mustache @@ -16,7 +16,7 @@ import io.micronaut.http.uri.UriTemplate import io.micronaut.http.cookie.Cookie import io.micronaut.http.client.multipart.MultipartBody import io.micronaut.core.type.Argument -import jakarta.inject.Inject +import {{javaxPackage}}.inject.Inject import spock.lang.Specification import spock.lang.Ignore {{#reactive}} diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/server/test/controller_test.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/server/test/controller_test.mustache index 84e1c76912..e7718c8c75 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/server/test/controller_test.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/server/test/controller_test.mustache @@ -19,7 +19,7 @@ import io.micronaut.core.type.GenericArgument; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Assertions; -import jakarta.inject.Inject; +import {{javaxPackage}}.inject.Inject; {{#reactive}} import reactor.core.publisher.Mono; import reactor.core.publisher.Flux; diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/auth/AuthorizationBinder.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/auth/AuthorizationBinder.mustache index 03e66a2f14..70ffa0abdb 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/auth/AuthorizationBinder.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/client/auth/AuthorizationBinder.mustache @@ -8,7 +8,7 @@ import io.micronaut.core.naming.NameUtils import io.micronaut.http.MutableHttpRequest import io.micronaut.http.client.bind.AnnotatedClientRequestBinder import io.micronaut.http.client.bind.ClientRequestUriContext -import jakarta.inject.Singleton +import {{javaxPackage}}.inject.Singleton {{#generatedAnnotation}} import {{javaxPackage}}.annotation.Generated {{/generatedAnnotation}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/test/controller_test.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/test/controller_test.mustache index d83bb0e6a2..7d22a14f4e 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/test/controller_test.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/server/test/controller_test.mustache @@ -19,7 +19,7 @@ import io.micronaut.core.type.Argument import org.junit.jupiter.api.Test import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Assertions -import jakarta.inject.Inject +import {{javaxPackage}}.inject.Inject {{#reactive}} import reactor.core.publisher.Flux {{/reactive}}