diff --git a/src/main/resources/handlebars/JavaSpring/api.mustache b/src/main/resources/handlebars/JavaSpring/api.mustache index 08a3bfd92c..6546e1008d 100644 --- a/src/main/resources/handlebars/JavaSpring/api.mustache +++ b/src/main/resources/handlebars/JavaSpring/api.mustache @@ -44,7 +44,12 @@ import org.springframework.web.multipart.MultipartFile; import org.springframework.web.bind.annotation.CookieValue; {{#jdk8-no-delegate}} +{{#jakarta}} +import jakarta.servlet.http.HttpServletRequest; +{{/jakarta}} +{{^jakarta}} import javax.servlet.http.HttpServletRequest; +{{/jakarta}} {{/jdk8-no-delegate}} {{#useBeanValidation}} {{#jakarta}} diff --git a/src/test/java/io/swagger/codegen/v3/generators/java/SpringGeneratorCodegenTest.java b/src/test/java/io/swagger/codegen/v3/generators/java/SpringGeneratorCodegenTest.java index 8ebeb1fc54..2717890eca 100644 --- a/src/test/java/io/swagger/codegen/v3/generators/java/SpringGeneratorCodegenTest.java +++ b/src/test/java/io/swagger/codegen/v3/generators/java/SpringGeneratorCodegenTest.java @@ -1,6 +1,7 @@ package io.swagger.codegen.v3.generators.java; import static io.swagger.codegen.v3.generators.java.AbstractJavaCodegen.JAKARTA; +import static io.swagger.codegen.v3.generators.java.AbstractJavaCodegen.JAVA8_MODE; import io.swagger.codegen.v3.ClientOptInput; import io.swagger.codegen.v3.CodegenArgument; @@ -29,10 +30,10 @@ public void testParameterOrdersUseOas2() throws Exception { .setOutputDir(output.getAbsolutePath()); configurator.setCodegenArguments(Collections.singletonList( - new CodegenArgument() - .option(CodegenConstants.USE_OAS2_OPTION) - .type("boolean") - .value(Boolean.TRUE.toString()))); + new CodegenArgument() + .option(CodegenConstants.USE_OAS2_OPTION) + .type("boolean") + .value(Boolean.TRUE.toString()))); final ClientOptInput clientOptInput = configurator.toClientOptInput(); new DefaultGenerator().opts(clientOptInput).generate(); @@ -88,10 +89,10 @@ public void testOas2AndJakarta() throws Exception { final File output = folder.getRoot(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setLang("spring") - .setInputSpecURL("src/test/resources/3_0_0/parameterOrder.yaml") - .setOutputDir(output.getAbsolutePath()) - .addAdditionalProperty(JAKARTA, true); + .setLang("spring") + .setInputSpecURL("src/test/resources/3_0_0/parameterOrder.yaml") + .setOutputDir(output.getAbsolutePath()) + .addAdditionalProperty(JAKARTA, true); configurator.setCodegenArguments(Collections.singletonList( new CodegenArgument() @@ -124,10 +125,10 @@ public void testUseOas3AndJakarta() throws Exception { final File output = folder.getRoot(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setLang("spring") - .setInputSpecURL("src/test/resources/3_0_0/parameterOrder.yaml") - .setOutputDir(output.getAbsolutePath()) - .addAdditionalProperty(JAKARTA, true); + .setLang("spring") + .setInputSpecURL("src/test/resources/3_0_0/parameterOrder.yaml") + .setOutputDir(output.getAbsolutePath()) + .addAdditionalProperty(JAKARTA, true); final ClientOptInput clientOptInput = configurator.toClientOptInput(); new DefaultGenerator().opts(clientOptInput).generate(); @@ -148,4 +149,52 @@ public void testUseOas3AndJakarta() throws Exception { folder.delete(); } + @Test(description = "verify java8 & jakarta") + public void testJava8Jakarta() throws Exception { + final TemporaryFolder folder = new TemporaryFolder(); + folder.create(); + final File output = folder.getRoot(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setLang("spring") + .setInputSpecURL("src/test/resources/3_0_0/parameterOrder.yaml") + .setOutputDir(output.getAbsolutePath()) + .addAdditionalProperty(JAKARTA, true) + .addAdditionalProperty(JAVA8_MODE, true); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + new DefaultGenerator().opts(clientOptInput).generate(); + + final File adminApiFile = new File(output, "/src/main/java/io/swagger/api/AdminApi.java"); + final String contentAdminApi = FileUtils.readFileToString(adminApiFile); + + Assert.assertTrue(contentAdminApi.contains("import jakarta.servlet.http.HttpServletRequest;")); + + folder.delete(); + } + + @Test(description = "verify java8 & javax") + public void testJava8Javax() throws Exception { + final TemporaryFolder folder = new TemporaryFolder(); + folder.create(); + final File output = folder.getRoot(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setLang("spring") + .setInputSpecURL("src/test/resources/3_0_0/parameterOrder.yaml") + .setOutputDir(output.getAbsolutePath()) + .addAdditionalProperty(JAKARTA, false) + .addAdditionalProperty(JAVA8_MODE, true); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + new DefaultGenerator().opts(clientOptInput).generate(); + + final File adminApiFile = new File(output, "/src/main/java/io/swagger/api/AdminApi.java"); + final String contentAdminApi = FileUtils.readFileToString(adminApiFile); + + Assert.assertTrue(contentAdminApi.contains("import javax.servlet.http.HttpServletRequest;")); + + folder.delete(); + } + }