Skip to content
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

Tgillain bug/1167 jakarta java8 #1180

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/resources/handlebars/JavaSpring/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}

}