Skip to content

Commit 701b295

Browse files
committed
add jakarta implementation
#1054
1 parent a212015 commit 701b295

23 files changed

+119
-22
lines changed

src/main/java/io/swagger/codegen/v3/generators/java/AbstractJavaCodegen.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegenConfig {
6262

6363
public static final String WIREMOCK_OPTION = "wiremock";
6464

65+
public static final String JAKARTA = "jakarta";
66+
6567
protected String dateLibrary = "threetenbp";
6668
protected boolean java8Mode = false;
6769
protected boolean java11Mode = false;
@@ -93,6 +95,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegenConfig {
9395
protected String apiDocPath = "docs/";
9496
protected String modelDocPath = "docs/";
9597
protected boolean supportJava6= false;
98+
protected boolean jakarta = false;
9699
private NotNullAnnotationFeatures notNullOption;
97100

98101
public AbstractJavaCodegen() {
@@ -194,6 +197,15 @@ public AbstractJavaCodegen() {
194197
cliOptions.add(CliOption.newBoolean(CHECK_DUPLICATED_MODEL_NAME, "Check if there are duplicated model names (ignoring case)"));
195198

196199
cliOptions.add(CliOption.newBoolean(WIREMOCK_OPTION, "Use wiremock to generate endpoint calls to mock on generated tests."));
200+
201+
cliOptions.add(CliOption.newBoolean(JAKARTA, "Use Jakarta EE (package jakarta.*) instead of Java EE (javax.*)"));
202+
203+
CliOption jeeSpec = CliOption.newBoolean(JAKARTA, "Use Jakarta EE (package jakarta.*) instead of Java EE (javax.*)");
204+
Map<String, String> jeeSpecModeOptions = new HashMap<String, String>();
205+
jeeSpecModeOptions.put("true", "Use Jakarta EE (package jakarta.*)");
206+
jeeSpecModeOptions.put("false", "Use Java EE (javax.*)");
207+
jeeSpec.setEnum(jeeSpecModeOptions);
208+
cliOptions.add(jeeSpec);
197209
}
198210

199211
@Override
@@ -490,6 +502,9 @@ public void processOpts() {
490502
} else if (dateLibrary.equals("legacy")) {
491503
additionalProperties.put("legacyDates", true);
492504
}
505+
506+
setJakarta(Boolean.parseBoolean(String.valueOf(additionalProperties.get(JAKARTA))));
507+
additionalProperties.put(JAKARTA, jakarta);
493508
}
494509

495510
private void sanitizeConfig() {
@@ -1564,6 +1579,10 @@ public void setJava11Mode(boolean java11Mode) {
15641579
this.java11Mode = java11Mode;
15651580
}
15661581

1582+
public void setJakarta(boolean jakarta) {
1583+
this.jakarta = jakarta;
1584+
}
1585+
15671586
@Override
15681587
public String escapeQuotationMark(String input) {
15691588
// remove " to avoid code injection

src/main/resources/handlebars/Java/ApiClient.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ import com.sun.jersey.api.client.WebResource.Builder;
2929
import com.sun.jersey.multipart.FormDataMultiPart;
3030
import com.sun.jersey.multipart.file.FileDataBodyPart;
3131

32+
{{#jakarta}}
33+
import jakarta.ws.rs.core.Response.Status.Family;
34+
import jakarta.ws.rs.core.MediaType;
35+
{{/jakarta}}
36+
{{^jakarta}}
3237
import javax.ws.rs.core.Response.Status.Family;
3338
import javax.ws.rs.core.MediaType;
39+
{{/jakarta}}
3440

3541
import java.util.Collection;
3642
import java.util.Collections;

src/main/resources/handlebars/Java/BeanValidationException.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package {{invokerPackage}};
22

33
import java.util.Set;
4-
4+
{{#jakarta}}
5+
import jakarta.validation.ConstraintViolation;
6+
import jakarta.validation.ValidationException;
7+
{{/jakarta}}
8+
{{^jakarta}}
59
import javax.validation.ConstraintViolation;
610
import javax.validation.ValidationException;
11+
{{/jakarta}}
712

813
public class BeanValidationException extends ValidationException {
914
/**

src/main/resources/handlebars/Java/build.gradle.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if(hasProperty('target') && target == 'android') {
5454
}
5555

5656
dependencies {
57-
provided 'javax.annotation:jsr250-api:1.0'
57+
provided 'jakarta.annotation:jakarta.annotation-api:{{#jakarta}}2.1.1{{/jakarta}}{{^jakarta}}1.3.5{{/jakarta}}'
5858
}
5959
}
6060

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}}
1+
{{^hideGenerationTimestamp}}@{{#jakarta}}jakarta{{/jakarta}}{{^jakarta}}javax{{/jakarta}}.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}}

src/main/resources/handlebars/Java/libraries/feign/build.gradle.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if(hasProperty('target') && target == 'android') {
5454
}
5555

5656
dependencies {
57-
provided 'javax.annotation:jsr250-api:1.0'
57+
provided 'jakarta.annotation:jakarta.annotation-api:{{#jakarta}}2.1.1{{/jakarta}}{{^jakarta}}1.3.5{{/jakarta}}'
5858
}
5959
}
6060

src/main/resources/handlebars/Java/libraries/jersey2/ApiClient.mustache

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package {{invokerPackage}};
22

3+
{{#jakarta}}
4+
import jakarta.ws.rs.client.Client;
5+
import jakarta.ws.rs.client.ClientBuilder;
6+
import jakarta.ws.rs.client.Entity;
7+
import jakarta.ws.rs.client.Invocation;
8+
import jakarta.ws.rs.client.WebTarget;
9+
import jakarta.ws.rs.core.Form;
10+
import jakarta.ws.rs.core.GenericType;
11+
import jakarta.ws.rs.core.MediaType;
12+
import jakarta.ws.rs.core.Response;
13+
import jakarta.ws.rs.core.Response.Status;
14+
{{/jakarta}}
15+
{{^jakarta}}
316
import javax.ws.rs.client.Client;
417
import javax.ws.rs.client.ClientBuilder;
518
import javax.ws.rs.client.Entity;
@@ -10,6 +23,7 @@ import javax.ws.rs.core.GenericType;
1023
import javax.ws.rs.core.MediaType;
1124
import javax.ws.rs.core.Response;
1225
import javax.ws.rs.core.Response.Status;
26+
{{/jakarta}}
1327

1428
import org.glassfish.jersey.client.ClientConfig;
1529
import org.glassfish.jersey.client.ClientProperties;

src/main/resources/handlebars/Java/libraries/jersey2/JSON.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
1717

1818
import java.text.DateFormat;
1919

20+
{{#jakarta}}
21+
import jakarta.ws.rs.ext.ContextResolver;
22+
{{/jakarta}}
23+
{{^jakarta}}
2024
import javax.ws.rs.ext.ContextResolver;
25+
{{/jakarta}}
2126

2227
{{>generatedAnnotation}}
2328
public class JSON implements ContextResolver<ObjectMapper> {

src/main/resources/handlebars/Java/libraries/jersey2/api.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import {{invokerPackage}}.ApiClient;
55
import {{invokerPackage}}.Configuration;
66
import {{invokerPackage}}.Pair;
77

8+
{{#jakarta}}
9+
import jakarta.ws.rs.core.GenericType;
10+
{{/jakarta}}
11+
{{^jakarta}}
812
import javax.ws.rs.core.GenericType;
13+
{{/jakarta}}
914

1015
{{#imports}}import {{import}};
1116
{{/imports}}

src/main/resources/handlebars/Java/libraries/jersey2/build.gradle.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if(hasProperty('target') && target == 'android') {
5454
}
5555

5656
dependencies {
57-
provided 'javax.annotation:jsr250-api:1.0'
57+
provided 'jakarta.annotation:jakarta.annotation-api:{{#jakarta}}2.1.1{{/jakarta}}{{^jakarta}}1.3.5{{/jakarta}}'
5858
}
5959
}
6060

0 commit comments

Comments
 (0)