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

[Java] internal config option to use jakarta or javax package #14310

Merged
merged 1 commit into from
Dec 30, 2022
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
2 changes: 1 addition & 1 deletion docs/generators/java-camel.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |true|
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
|useOptional|Use Optional container for optional parameters| |false|
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports).| |true|
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports).| |false|
|useSpringController|Annotate the generated API as a Spring Controller| |false|
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
|useTags|use tags for creating interface and controller classnames| |false|
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |true|
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
|useOptional|Use Optional container for optional parameters| |false|
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports).| |true|
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports).| |false|
|useSpringController|Annotate the generated API as a Spring Controller| |false|
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
|useTags|use tags for creating interface and controller classnames| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6455,7 +6455,7 @@ public boolean convertPropertyToBoolean(String propertyKey) {
return result;
}

public void writePropertyBack(String propertyKey, boolean value) {
public void writePropertyBack(String propertyKey, Object value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @OpenAPITools/generator-core-team

additionalProperties.put(propertyKey, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
public static final String TEST_OUTPUT = "testOutput";
public static final String IMPLICIT_HEADERS = "implicitHeaders";
public static final String IMPLICIT_HEADERS_REGEX = "implicitHeadersRegex";
public static final String JAVAX_PACKAGE = "javaxPackage";

public static final String CAMEL_CASE_DOLLAR_SIGN = "camelCaseDollarSign";

Expand Down Expand Up @@ -670,6 +671,8 @@ public void processOpts() {
if (additionalProperties.containsKey(TEST_OUTPUT)) {
setOutputTestFolder(additionalProperties.get(TEST_OUTPUT).toString());
}

applyJavaxPackage();
}

@Override
Expand Down Expand Up @@ -721,6 +724,14 @@ private void sanitizeConfig() {
}
}

protected void applyJavaxPackage() {
writePropertyBack(JAVAX_PACKAGE, "javax");
}

protected void applyJakartaPackage() {
writePropertyBack(JAVAX_PACKAGE, "jakarta");
}

@Override
public String escapeReservedWord(String name) {
if (this.reservedWordsMappings().containsKey(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public void processOpts() {
// The flag below should be set for all Java libraries, but the templates need to be ported
// one by one for each library.
supportsAdditionalPropertiesWithComposedSchema = true;

applyJakartaPackage();
} else if (NATIVE.equals(getLibrary())) {
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public class SpringCodegen extends AbstractJavaCodegen
public static final String RETURN_SUCCESS_CODE = "returnSuccessCode";
public static final String UNHANDLED_EXCEPTION_HANDLING = "unhandledException";
public static final String USE_SPRING_BOOT3 = "useSpringBoot3";
public static final String USE_JAKARTA_EE = "useJakartaEe";
public static final String REQUEST_MAPPING_OPTION = "requestMappingMode";
public static final String USE_REQUEST_MAPPING_ON_CONTROLLER = "useRequestMappingOnController";
public static final String USE_REQUEST_MAPPING_ON_INTERFACE = "useRequestMappingOnInterface";
Expand Down Expand Up @@ -243,7 +242,7 @@ public SpringCodegen() {
useSwaggerUI));
cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT3,
"Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports).",
useSwaggerUI));
useSpringBoot3));

supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
supportedLibraries.put(SPRING_CLOUD_LIBRARY,
Expand Down Expand Up @@ -474,9 +473,7 @@ public void processOpts() {
if (AnnotationLibrary.SWAGGER1.equals(getAnnotationLibrary())) {
throw new IllegalArgumentException(AnnotationLibrary.SWAGGER1.getPropertyName() + " is not supported with Spring Boot > 3.x");
}
writePropertyBack(USE_JAKARTA_EE, true);
} else {
writePropertyBack(USE_JAKARTA_EE, false);
applyJakartaPackage();
}
writePropertyBack(USE_SPRING_BOOT3, isUseSpringBoot3());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;

import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.core.MediaType;
import {{javaxPackage}}.ws.rs.core.Cookie;
import {{javaxPackage}}.ws.rs.core.Response.Status.Family;
import {{javaxPackage}}.ws.rs.core.MediaType;

import java.util.Collection;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package {{invokerPackage}};

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.ValidationException;
import {{javaxPackage}}.validation.ConstraintViolation;
import {{javaxPackage}}.validation.ValidationException;

public class BeanValidationException extends ValidationException {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@javax.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}})
@{{javaxPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}})
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.google.api.client.http.HttpMethods;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.json.Json;

import javax.ws.rs.core.UriBuilder;
import {{javaxPackage}}.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {{invokerPackage}}.ApiException;
import java.util.Objects;
import java.lang.reflect.Type;
import java.util.Map;
import javax.ws.rs.core.GenericType;
import {{javaxPackage}}.ws.rs.core.GenericType;

import com.fasterxml.jackson.annotation.JsonValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package {{invokerPackage}};

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import {{javaxPackage}}.ws.rs.client.Client;
import {{javaxPackage}}.ws.rs.client.ClientBuilder;
import {{javaxPackage}}.ws.rs.client.Entity;
import {{javaxPackage}}.ws.rs.client.Invocation;
import {{javaxPackage}}.ws.rs.client.WebTarget;
import {{javaxPackage}}.ws.rs.core.Form;
import {{javaxPackage}}.ws.rs.core.GenericType;
import {{javaxPackage}}.ws.rs.core.MediaType;
import {{javaxPackage}}.ws.rs.core.Response;
import {{javaxPackage}}.ws.rs.core.Response.Status;

{{#hasOAuthMethods}}
import com.github.scribejava.core.model.OAuth2AccessToken;
Expand All @@ -27,9 +27,9 @@ import java.io.IOException;
import java.io.InputStream;

import java.net.URI;
import javax.net.ssl.SSLContext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javax.net.ssl package ist unaffected by Jakarta EE.
This change should be reverted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for spotting. I've create PR for fix this #14341

import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import {{javaxPackage}}.net.ssl.SSLContext;
import {{javaxPackage}}.net.ssl.TrustManager;
import {{javaxPackage}}.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -251,7 +251,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* <p>Getter for the field <code>httpClient</code>.</p>
*
* @return a {@link javax.ws.rs.client.Client} object.
* @return a {@link {{javaxPackage}}.ws.rs.client.Client} object.
*/
public Client getHttpClient() {
return httpClient;
Expand All @@ -260,7 +260,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* <p>Setter for the field <code>httpClient</code>.</p>
*
* @param httpClient a {@link javax.ws.rs.client.Client} object.
* @param httpClient a {@link {{javaxPackage}}.ws.rs.client.Client} object.
* @return a {@link org.openapitools.client.ApiClient} object.
*/
public ApiClient setHttpClient(Client httpClient) {
Expand Down Expand Up @@ -1098,7 +1098,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* <p>Prepare the file for download from the response.</p>
*
* @param response a {@link javax.ws.rs.core.Response} object.
* @param response a {@link {{javaxPackage}}.ws.rs.core.Response} object.
* @return a {@link java.io.File} object.
* @throws java.io.IOException if any.
*/
Expand Down Expand Up @@ -1387,7 +1387,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
* To completely disable certificate validation (at your own risk), you can
* override this method and invoke disableCertificateValidation(clientBuilder).
*
* @param clientBuilder a {@link javax.ws.rs.client.ClientBuilder} object.
* @param clientBuilder a {@link {{javaxPackage}}.ws.rs.client.ClientBuilder} object.
*/
protected void customizeClientBuilder(ClientBuilder clientBuilder) {
// No-op extension point
Expand All @@ -1399,7 +1399,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
* Please note that trusting all certificates is extremely risky.
* This may be useful in a development environment with self-signed certificates.
*
* @param clientBuilder a {@link javax.ws.rs.client.ClientBuilder} object.
* @param clientBuilder a {@link {{javaxPackage}}.ws.rs.client.ClientBuilder} object.
* @throws java.security.KeyManagementException if any.
* @throws java.security.NoSuchAlgorithmException if any.
*/
Expand All @@ -1426,7 +1426,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
/**
* <p>Build the response headers.</p>
*
* @param response a {@link javax.ws.rs.core.Response} object.
* @param response a {@link {{javaxPackage}}.ws.rs.core.Response} object.
* @return a {@link java.util.Map} of response headers.
*/
protected Map<String, List<String>> buildResponseHeaders(Response response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.ContextResolver;
import {{javaxPackage}}.ws.rs.core.GenericType;
import {{javaxPackage}}.ws.rs.ext.ContextResolver;

{{>generatedAnnotation}}
public class JSON implements ContextResolver<ObjectMapper> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import {{javaxPackage}}.ws.rs.core.GenericType;
import {{javaxPackage}}.ws.rs.core.Response;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {{invokerPackage}}.ApiResponse;
import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.Pair;

import javax.ws.rs.core.GenericType;
import {{javaxPackage}}.ws.rs.core.GenericType;

{{#imports}}import {{import}};
{{/imports}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.github.scribejava.core.exceptions.OAuthException;
import com.github.scribejava.core.model.OAuth2AccessToken;
import com.github.scribejava.core.oauth.OAuth20Service;

import javax.ws.rs.core.UriBuilder;
import {{javaxPackage}}.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ import com.fasterxml.jackson.annotation.JsonCreator;
{{/vendorExtensions.x-has-readonly-properties}}
{{/jackson}}
{{#withXml}}
import javax.xml.bind.annotation.*;
import {{javaxPackage}}.xml.bind.annotation.*;
{{/withXml}}
{{#parcelableModel}}
import android.os.Parcelable;
import android.os.Parcel;
{{/parcelableModel}}
{{#useBeanValidation}}
import javax.validation.constraints.*;
import javax.validation.Valid;
import {{javaxPackage}}.validation.constraints.*;
import {{javaxPackage}}.validation.Valid;
{{/useBeanValidation}}
{{#performBeanValidation}}
import org.hibernate.validator.constraints.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import {{javaxPackage}}.ws.rs.core.GenericType;
import {{javaxPackage}}.ws.rs.core.Response;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{/deprecated}}
{{#required}}
{{#isNullable}}
@javax.annotation.Nullable
@{{javaxPackage}}.annotation.Nullable
{{/isNullable}}
{{^isNullable}}
@javax.annotation.Nonnull
@{{javaxPackage}}.annotation.Nonnull
{{/isNullable}}
{{/required}}
{{^required}}
@javax.annotation.Nullable
@{{javaxPackage}}.annotation.Nullable
{{/required}}
{{#useBeanValidation}}
{{>beanValidation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {{invokerPackage}}.ApiException;
import java.util.Objects;
import java.lang.reflect.Type;
import java.util.Map;
import jakarta.ws.rs.core.GenericType;
import {{javaxPackage}}.ws.rs.core.GenericType;

import com.fasterxml.jackson.annotation.JsonValue;

Expand Down
Loading