Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions bin/configs/java-restclient-springBoot4-jackson2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: java
outputDir: samples/client/petstore/java/restclient-springBoot4-jackson2
library: restclient
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: petstore-restclient
hideGenerationTimestamp: "true"
containerDefaultToNull: "true"
useSpringBoot4: true
12 changes: 12 additions & 0 deletions bin/configs/java-restclient-springBoot4-jackson3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: java
outputDir: samples/client/petstore/java/restclient-springBoot4-jackson3
library: restclient
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: petstore-restclient
hideGenerationTimestamp: "true"
containerDefaultToNull: "true"
useSpringBoot4: true
useJackson3: true
openApiNullable: false
12 changes: 12 additions & 0 deletions bin/configs/java-webclient-springBoot4-jackson3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: java
outputDir: samples/client/petstore/java/webclient-springBoot4-jackson3
library: webclient
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: petstore-webclient
hideGenerationTimestamp: "true"
containerDefaultToNull: "true"
useSpringBoot4: true
useJackson3: true
openApiNullable: false
2 changes: 2 additions & 0 deletions docs/generators/java-microprofile.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |false|
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useGzipFeature|Send gzip-encoded requests| |false|
|useJackson3|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, jersey3, native, okhttp-gson support this option.| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
Expand All @@ -107,6 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
|useSingleRequestParameter|Setting this property to "true" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY native, jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to "static" does the same as "true", but also makes the generated arguments class static with single parameter instantiation.| |false|
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
|useUnaryInterceptor|If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption| |false|
|webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false|
|withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false|
Expand Down
2 changes: 2 additions & 0 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |false|
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useGzipFeature|Send gzip-encoded requests| |false|
|useJackson3|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, jersey3, native, okhttp-gson support this option.| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
Expand All @@ -107,6 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
|useSingleRequestParameter|Setting this property to "true" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY native, jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to "static" does the same as "true", but also makes the generated arguments class static with single parameter instantiation.| |false|
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
|useUnaryInterceptor|If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption| |false|
|webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false|
|withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false|
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
devShells.default = pkgs.mkShell
{
buildInputs = with pkgs;[
jdk11
jdk17
maven
];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import static java.util.Collections.sort;
import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY;
import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
import static org.openapitools.codegen.utils.StringUtils.camelize;
Expand Down Expand Up @@ -117,6 +118,12 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String SERIALIZATION_LIBRARY_JACKSON = "jackson";
public static final String SERIALIZATION_LIBRARY_JSONB = "jsonb";

public static final String USE_SPRING_BOOT4 = "useSpringBoot4";
public static final String USE_JACKSON_3 = "useJackson3";
private static final String JACKSON2_PACKAGE = "com.fasterxml.jackson";
private static final String JACKSON3_PACKAGE = "tools.jackson";
private static final String JACKSON_PACKAGE = "jacksonPackage";

public static final String GENERATE_CLIENT_AS_BEAN = "generateClientAsBean";

protected String gradleWrapperPackage = "gradle.wrapper";
Expand All @@ -134,7 +141,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
@Setter protected boolean microProfileRegisterExceptionMapper = true;
@Setter protected String configKey = null;
@Setter(AccessLevel.PRIVATE) protected boolean configKeyFromClassName = false;

@Setter protected boolean asyncNative = false;
@Setter protected boolean parcelableModel = false;
@Setter protected boolean performBeanValidation = false;
Expand All @@ -158,6 +164,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen
* Serialization library.
*/
@Getter protected String serializationLibrary = null;
@Getter @Setter protected boolean useSpringBoot4 = false;
@Getter @Setter protected boolean useJackson3 = false;
@Setter protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
protected String rootJavaEEPackage;
protected Map<String, MpRestClientVersion> mpRestClientVersions = new LinkedHashMap<>();
Expand Down Expand Up @@ -298,8 +306,8 @@ public JavaClientCodegen() {
serializationOptions.put(SERIALIZATION_LIBRARY_JSONB, "Use JSON-B as serialization library");
serializationLibrary.setEnum(serializationOptions);
cliOptions.add(serializationLibrary);

// Ensure the OAS 3.x discriminator mappings include any descendent schemas that allOf
cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT4, "Generate code and provide dependencies for use with Spring Boot 4.x.", useSpringBoot4));
cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Set it in order to use jackson 3 dependencies (only allowed when `" + USE_SPRING_BOOT4 + "` is set and incompatible with `"+OPENAPI_NULLABLE+"`).", useJackson3)); // Ensure the OAS 3.x discriminator mappings include any descendent schemas that allOf
// inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values,
// and the discriminator mapping schemas in the OAS document.
this.setLegacyDiscriminatorBehavior(false);
Expand Down Expand Up @@ -367,8 +375,29 @@ public void processOpts() {
// default jackson unless overridden by setSerializationLibrary
this.jackson = !additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY) ||
SERIALIZATION_LIBRARY_JACKSON.equals(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY));

convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup);
convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3);
convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4, this::setUseSpringBoot4);
if(isUseJackson3() && !isUseSpringBoot4()){
throw new IllegalArgumentException("useJackson3 is only available with Spring Boot >= 4");
}
if(isUseJackson3() && isOpenApiNullable()){
throw new IllegalArgumentException("openApiNullable cannot be set with useJackson3");
}

if(this.useJackson3){
this.applyJackson3Package();
} else {
this.applyJackson2Package();
}

if(this.useSpringBoot4) {
setUseJakartaEe(true);
applyJakartaPackage();
}

// override parent one
importMapping.put("JsonDeserialize", (useJackson3 ? JACKSON3_PACKAGE : JACKSON2_PACKAGE) + ".databind.annotation.JsonDeserialize");

// RxJava
if (additionalProperties.containsKey(USE_RX_JAVA2) && additionalProperties.containsKey(USE_RX_JAVA3)) {
Expand Down Expand Up @@ -790,8 +819,10 @@ public void processOpts() {
additionalProperties.remove(SERIALIZATION_LIBRARY_GSON);
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", invokerFolder, "RFC3339DateFormat.java"));
supportingFiles.add(new SupportingFile("RFC3339InstantDeserializer.mustache", invokerFolder, "RFC3339InstantDeserializer.java"));
supportingFiles.add(new SupportingFile("RFC3339JavaTimeModule.mustache", invokerFolder, "RFC3339JavaTimeModule.java"));
if (!useJackson3) {
supportingFiles.add(new SupportingFile("RFC3339InstantDeserializer.mustache", invokerFolder, "RFC3339InstantDeserializer.java"));
supportingFiles.add(new SupportingFile("RFC3339JavaTimeModule.mustache", invokerFolder, "RFC3339JavaTimeModule.java"));
}
break;
case SERIALIZATION_LIBRARY_GSON:
additionalProperties.put(SERIALIZATION_LIBRARY_GSON, "true");
Expand All @@ -809,7 +840,7 @@ public void processOpts() {
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
break;
}

if (isLibrary(FEIGN)) {
additionalProperties.put("feign-okhttp", "true");
} else if (isLibrary(FEIGN_HC5)) {
Expand Down Expand Up @@ -1028,6 +1059,7 @@ private static boolean isMultipartType(List<Map<String, String>> consumes) {
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);

if (!model.isEnum) {
//Needed imports for Jackson based libraries
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
Expand Down Expand Up @@ -1241,6 +1273,14 @@ public void setCaseInsensitiveResponseHeaders(final Boolean caseInsensitiveRespo
this.caseInsensitiveResponseHeaders = caseInsensitiveResponseHeaders;
}

protected void applyJackson2Package() {
writePropertyBack(JACKSON_PACKAGE, JACKSON2_PACKAGE);
}

protected void applyJackson3Package() {
writePropertyBack(JACKSON_PACKAGE, JACKSON3_PACKAGE);
}

public void setSerializationLibrary(String serializationLibrary) {
if (SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) {
this.serializationLibrary = SERIALIZATION_LIBRARY_JACKSON;
Expand Down Expand Up @@ -1281,7 +1321,7 @@ public String toApiVarName(String name) {

@Override
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
if(additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo", "JsonIgnoreProperties")) {
Map<String, String> oneImport = new HashMap<>();
oneImport.put("import", importMapping.get(i));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{>licenseInfo}}
package {{invokerPackage}};

import com.fasterxml.jackson.databind.util.StdDateFormat;
import {{jacksonPackage}}.databind.util.StdDateFormat;

import java.text.DateFormat;
import java.text.FieldPosition;
Expand Down
Loading
Loading